List test files matching a pattern. Examples: * List all test files: tools ts pytest list * Find loader tests: tools ts pytest list --pattern '**/test_loader*.py' * Search in specific directory: tools ts pytest list --pattern 'test_*.py' --pa
(
ctx: Context,
pattern: str = "test_*.py",
path: str = None,
)
| 224 | }, |
| 225 | ) |
| 226 | def list_tests( |
| 227 | ctx: Context, |
| 228 | pattern: str = "test_*.py", |
| 229 | path: str = None, |
| 230 | ): |
| 231 | """ |
| 232 | List test files matching a pattern. |
| 233 | |
| 234 | Examples: |
| 235 | |
| 236 | * List all test files: |
| 237 | |
| 238 | tools ts pytest list |
| 239 | |
| 240 | * Find loader tests: |
| 241 | |
| 242 | tools ts pytest list --pattern '**/test_loader*.py' |
| 243 | |
| 244 | * Search in specific directory: |
| 245 | |
| 246 | tools ts pytest list --pattern 'test_*.py' --path tests/pytests/unit |
| 247 | """ |
| 248 | if path is None: |
| 249 | search_path = tools.utils.REPO_ROOT / "tests" / "pytests" |
| 250 | else: |
| 251 | search_path = tools.utils.REPO_ROOT / path |
| 252 | |
| 253 | if not search_path.exists(): |
| 254 | ctx.error(f"Path does not exist: {search_path}") |
| 255 | ctx.exit(1) |
| 256 | |
| 257 | ctx.info( |
| 258 | f"Searching for '{pattern}' in {search_path.relative_to(tools.utils.REPO_ROOT)}" |
| 259 | ) |
| 260 | |
| 261 | # Use glob to find matching files |
| 262 | matches = sorted(search_path.glob(pattern)) |
| 263 | |
| 264 | if not matches: |
| 265 | ctx.warn(f"No test files found matching '{pattern}'") |
| 266 | ctx.exit(0) |
| 267 | |
| 268 | ctx.info(f"Found {len(matches)} test file(s):") |
| 269 | for match in matches: |
| 270 | # Print relative to repo root |
| 271 | relative_path = match.relative_to(tools.utils.REPO_ROOT) |
| 272 | ctx.print(f" {relative_path}") |
| 273 | |
| 274 | ctx.exit(0) |