coderabbit changes

This commit is contained in:
Adam Outler
2026-01-03 20:13:01 +00:00
parent 850d93ed62
commit 3cf856f1c2
11 changed files with 104 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
import os
import pathlib
import subprocess
import shutil
import pytest
@@ -13,8 +14,48 @@ def _announce(request: pytest.FixtureRequest, message: str) -> None:
print(message)
def _clean_test_mounts(project_root: pathlib.Path) -> None:
"""Clean up the test_mounts directory, handling root-owned files via Docker."""
mounts_dir = project_root / "test_mounts"
if not mounts_dir.exists():
return
# Try python removal first (faster)
try:
shutil.rmtree(mounts_dir)
except PermissionError:
# Fallback to docker for root-owned files
# We mount the parent directory to delete the directory itself
cmd = [
"docker", "run", "--rm",
"-v", f"{project_root}:/work",
"alpine:3.22",
"rm", "-rf", "/work/test_mounts"
]
subprocess.run(
cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=False
)
@pytest.fixture(scope="session")
def cleanup_artifacts(request: pytest.FixtureRequest) -> None:
"""Ensure test artifacts are cleaned up before and after the session."""
project_root = pathlib.Path(__file__).resolve().parents[2]
_announce(request, "[docker-tests] Cleaning up previous test artifacts...")
_clean_test_mounts(project_root)
yield
_announce(request, "[docker-tests] Cleaning up test artifacts...")
_clean_test_mounts(project_root)
@pytest.fixture(scope="session", autouse=True)
def build_netalertx_test_image(request: pytest.FixtureRequest) -> None:
def build_netalertx_test_image(request: pytest.FixtureRequest, cleanup_artifacts: None) -> None:
"""Build the docker test image before running any docker-based tests."""
image = os.environ.get("NETALERTX_TEST_IMAGE", "netalertx-test")