This commit is contained in:
Ross
2026-06-15 09:26:17 +01:00
parent aaee3577ad
commit afd4cc3b87
5 changed files with 24 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
import os
import shutil
import pytest
from django.conf import settings
@pytest.fixture(scope="session", autouse=True)
def cleanup_test_media():
"""
Session-scoped fixture to automatically clean up temporary media files
generated during the test run.
"""
yield
# Clean up settings.MEDIA_ROOT
media_root = getattr(settings, "MEDIA_ROOT", None)
if media_root and os.path.exists(media_root) and "media_test" in media_root:
shutil.rmtree(media_root, ignore_errors=True)
# Also clean up any legacy directories created due to missing trailing slash
base_dir = getattr(settings, "BASE_DIR", None)
if base_dir:
legacy_dir = os.path.join(base_dir, "media_testlongs")
if os.path.exists(legacy_dir):
shutil.rmtree(legacy_dir, ignore_errors=True)
View File
View File
View File
+1 -1
View File
@@ -33,6 +33,6 @@ TASKS = {
}
# Local media root for tests to avoid container-only paths in settings_local
MEDIA_ROOT = os.path.join(BASE_DIR, "media_test")
MEDIA_ROOT = os.path.join(BASE_DIR, "media_test") + "/"
os.makedirs(MEDIA_ROOT, exist_ok=True)