mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2026-04-06 07:47:53 +10:00
Fix pytest basetemp handling in test harness
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user