Search upward in the directory tree to a maximum of three layers to find and return the package root (containing the 'tests' folder)
(start_path: pathlib.Path)
| 292 | |
| 293 | @positional_deprecated |
| 294 | def find_test_root(start_path: pathlib.Path) -> pathlib.Path: |
| 295 | """ |
| 296 | Search upward in the directory tree to a maximum of three layers |
| 297 | to find and return the package root (containing the 'tests' folder) |
| 298 | """ |
| 299 | cur_path = start_path.resolve() |
| 300 | max_layers = 3 |
| 301 | for _ in range(max_layers): |
| 302 | if (cur_path / "tests" / "test_version_stable.py").exists(): |
| 303 | return cur_path |
| 304 | else: |
| 305 | cur_path = cur_path.parent.resolve() |
| 306 | raise FileNotFoundError( |
| 307 | f"Unable to find package root within {max_layers} upwards" + f"of {start_path}" |
| 308 | ) |
| 309 | |
| 310 | |
| 311 | @positional_deprecated |