Fix pytest basetemp handling in test harness

This commit is contained in:
Nick Sweeting
2026-03-24 14:46:05 -07:00
parent ed1ddbc95e
commit 68d9e30c5f
2 changed files with 6 additions and 3 deletions

View File

@@ -16,16 +16,18 @@ import pytest
pytest_plugins = ["archivebox.tests.fixtures"]
REPO_ROOT = Path(__file__).resolve().parents[2]
PYTEST_BASETEMP_ROOT = (REPO_ROOT / "tests" / "out").resolve()
SESSION_DATA_DIR = Path(tempfile.mkdtemp(prefix="archivebox-pytest-session-")).resolve()
# Force ArchiveBox imports to see a temp DATA_DIR and cwd during test collection.
# Force ArchiveBox imports to see a temp DATA_DIR during test collection.
os.environ["DATA_DIR"] = str(SESSION_DATA_DIR)
os.environ.pop("CRAWL_DIR", None)
os.environ.pop("SNAP_DIR", None)
os.chdir(SESSION_DATA_DIR)
def _is_repo_path(path: Path) -> bool:
resolved = path.expanduser().resolve(strict=False)
if resolved == PYTEST_BASETEMP_ROOT or PYTEST_BASETEMP_ROOT in resolved.parents:
return False
return resolved == REPO_ROOT or REPO_ROOT in resolved.parents

View File

@@ -9,8 +9,9 @@ from archivebox.tests import conftest as test_harness
def test_session_data_dir_is_outside_repo_root():
assert test_harness.SESSION_DATA_DIR != test_harness.REPO_ROOT
assert test_harness.REPO_ROOT not in test_harness.SESSION_DATA_DIR.parents
assert test_harness.REPO_ROOT not in Path.cwd().parents
assert Path.cwd() != test_harness.REPO_ROOT
if test_harness.REPO_ROOT in Path.cwd().parents:
assert test_harness.PYTEST_BASETEMP_ROOT in (Path.cwd(), *Path.cwd().parents)
def test_cli_helpers_reject_repo_root_runtime_paths():