.
This commit is contained in:
+23
@@ -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)
|
||||||
@@ -33,6 +33,6 @@ TASKS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Local media root for tests to avoid container-only paths in settings_local
|
# 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)
|
os.makedirs(MEDIA_ROOT, exist_ok=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user