Get the pytest executable path from venv or system.
(ctx: Context, venv_path: str = None)
| 26 | |
| 27 | |
| 28 | def get_pytest_path(ctx: Context, venv_path: str = None) -> pathlib.Path | None: |
| 29 | """ |
| 30 | Get the pytest executable path from venv or system. |
| 31 | """ |
| 32 | if venv_path: |
| 33 | pytest_bin = pathlib.Path(venv_path) / "bin" / "pytest" |
| 34 | if pytest_bin.exists(): |
| 35 | return pytest_bin |
| 36 | else: |
| 37 | ctx.error(f"pytest not found in venv: {pytest_bin}") |
| 38 | return None |
| 39 | |
| 40 | # Try to find pytest in PATH |
| 41 | pytest_bin_str = shutil.which("pytest") |
| 42 | if pytest_bin_str: |
| 43 | return pathlib.Path(pytest_bin_str) |
| 44 | |
| 45 | # Try default venv310 |
| 46 | default_venv = tools.utils.REPO_ROOT / "venv310" / "bin" / "pytest" |
| 47 | if default_venv.exists(): |
| 48 | ctx.info(f"Using pytest from default venv: {default_venv}") |
| 49 | return default_venv |
| 50 | |
| 51 | ctx.error("pytest not found. Install pytest or provide --venv path") |
| 52 | return None |
| 53 | |
| 54 | |
| 55 | @pytest_cmd.command( |
no test coverage detected