Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Repository scripts imported by tests and development tools."""
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Local test helpers imported by subprocess-based integration tests."""
38 changes: 38 additions & 0 deletions tests/test_test_package_resolution.py
Original file line number Diff line number Diff line change
@@ -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
Loading