-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
featureNew feature or requestNew feature or request
Milestone
Description
Problem
Test containers are left behind when tests fail because fixture cleanup doesn't always run on hard failures or interrupts. This causes:
- Resource accumulation
make testfailures due to lingering container detection- Manual cleanup required after debugging
Proposed Solution
1. Add pytest option --keep-containers
def pytest_addoption(parser):
parser.addoption(
"--keep-containers",
action="store_true",
default=False,
help="Keep test containers after test completion (for debugging failed tests)",
)2. Use request.addfinalizer() for reliable cleanup
Replace yield-based cleanup with addfinalizer() which runs even on test failures:
@pytest.fixture(scope="function")
def devcontainer_up(initialized_workspace, request):
# ... setup code ...
def cleanup():
if request.config.getoption("--keep-containers"):
print(f"\n⚠️ Keeping container for debugging: {container_name}")
return
# ... existing cleanup code (podman compose down, etc.) ...
request.addfinalizer(cleanup)
yield workspace_pathUsage
# Normal run - auto-cleanup on success AND failure
make test-integration
# Debug mode - keep containers for investigation
uv run pytest tests/test_integration.py --keep-containers -x
# Inspect the failed container
podman exec -it <container_name> bash
# Clean up manually when done
make clean-test-containersBenefits
- Containers cleaned up reliably even on failures
--keep-containersflag for debugging- Works with
-x(stop on first failure) for debugging - No more manual cleanup after failed test runs
Affected Fixtures
devcontainer_updevcontainer_with_sidecarinitialized_workspace- Any other fixtures that create containers
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
featureNew feature or requestNew feature or request