Find test executables in the build directory
(build_dir: Path, specific_test: Optional[str] = None)
| 180 | |
| 181 | |
| 182 | def discover_tests(build_dir: Path, specific_test: Optional[str] = None) -> list[Path]: |
| 183 | """Find test executables in the build directory""" |
| 184 | # Check test directory |
| 185 | possible_test_dirs = [ |
| 186 | _PROJECT_ROOT / "tests" / "bin", # Python build system |
| 187 | ] |
| 188 | |
| 189 | test_dir = None |
| 190 | for possible_dir in possible_test_dirs: |
| 191 | if possible_dir.exists(): |
| 192 | # Check if this directory has actual executable test files |
| 193 | executable_tests = [ |
| 194 | f |
| 195 | for pattern in _get_test_patterns() |
| 196 | for f in possible_dir.glob(pattern) |
| 197 | if _is_test_executable(f) |
| 198 | ] |
| 199 | if executable_tests: |
| 200 | test_dir = possible_dir |
| 201 | break |
| 202 | |
| 203 | if not test_dir: |
| 204 | print(f"Error: No test directory found. Checked: {possible_test_dirs}") |
| 205 | sys.exit(1) |
| 206 | assert test_dir is not None |
| 207 | |
| 208 | test_files: list[Path] = [] |
| 209 | for pattern in _get_test_patterns(): |
| 210 | for test_file in test_dir.glob(pattern): |
| 211 | if not _is_test_executable(test_file): |
| 212 | continue |
| 213 | if specific_test: |
| 214 | # Support both "test_name" and "name" formats (case-insensitive) |
| 215 | test_stem = test_file.stem |
| 216 | test_name = test_stem.replace("test_", "") |
| 217 | if ( |
| 218 | test_stem.lower() == specific_test.lower() |
| 219 | or test_name.lower() == specific_test.lower() |
| 220 | ): |
| 221 | test_files.append(test_file) |
| 222 | else: |
| 223 | test_files.append(test_file) |
| 224 | |
| 225 | return test_files |
| 226 | |
| 227 | |
| 228 | def parse_args() -> Args: |
no test coverage detected