diff --git a/archivebox/tests/conftest.py b/archivebox/tests/conftest.py index b87818c2..deeb1208 100644 --- a/archivebox/tests/conftest.py +++ b/archivebox/tests/conftest.py @@ -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 diff --git a/archivebox/tests/test_test_harness.py b/archivebox/tests/test_test_harness.py index 686c31a9..22aace9d 100644 --- a/archivebox/tests/test_test_harness.py +++ b/archivebox/tests/test_test_harness.py @@ -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():