diff --git a/pyproject.toml b/pyproject.toml index 337f7d20..320e9312 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,7 @@ agentdescent = ["integrations/*.md", "integrations/*.json"] [tool.pytest.ini_options] testpaths = ["tests"] addopts = "-q" -# Put the repo root on sys.path so `import agentdescent` / `import examples` -# resolve under a bare `pytest` invocation (CI), not just `python -m pytest`. -pythonpath = ["."] +# Put both the repo root and tests directory on sys.path. The root resolves +# package imports; tests keeps legacy top-level test helpers importable after +# making `tests` an explicit package for subprocess-based refs. +pythonpath = [".", "tests"] diff --git a/scripts/__init__.py b/scripts/__init__.py new file mode 100644 index 00000000..d2b633e4 --- /dev/null +++ b/scripts/__init__.py @@ -0,0 +1 @@ +"""Repository scripts imported by tests and development tools.""" diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 00000000..229772d2 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +"""Local test helpers imported by subprocess-based integration tests.""" diff --git a/tests/test_test_package_resolution.py b/tests/test_test_package_resolution.py new file mode 100644 index 00000000..c4e9caef --- /dev/null +++ b/tests/test_test_package_resolution.py @@ -0,0 +1,38 @@ +"""Local test helpers must win over unrelated installed packages.""" + +import os +from pathlib import Path +import subprocess +import sys + + +ROOT = Path(__file__).resolve().parents[1] + + +def test_repository_test_and_script_packages_win_over_installed_packages(tmp_path): + fake_site = tmp_path / "site-packages" + for name in ("tests", "scripts"): + conflicting = fake_site / name + conflicting.mkdir(parents=True) + (conflicting / "__init__.py").write_text( + f"# simulated installed {name} package\n" + ) + + env = os.environ.copy() + env["PYTHONPATH"] = os.pathsep.join((str(fake_site), str(ROOT / "tests"))) + code = ( + "import tests.test_evolvespec, scripts.audit_workloads, faults, audit_ppi_cases; " + "import tests, scripts; print(tests.__file__); print(scripts.__file__)" + ) + result = subprocess.run( + [sys.executable, "-c", code], + cwd=ROOT, + env=env, + text=True, + capture_output=True, + check=False, + ) + + assert result.returncode == 0, result.stdout + result.stderr + assert str(ROOT / "tests" / "__init__.py") in result.stdout + assert str(ROOT / "scripts" / "__init__.py") in result.stdout