Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add test files cleanup

Paweł Zarębski82c6a77d02c5
diff --git a/tests/conftest.py b/tests/conftest.py
index 06cc82ff8b..50dcb85c97 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,7 +1,9 @@
from io import BytesIO
+from shutil import rmtree
from unittest.mock import MagicMock, Mock
import pytest
+from django.conf import settings as django_settings
from django.contrib.auth.models import Permission
from django.contrib.sites.models import Site
from django.core.files import File
@@ -40,6 +42,18 @@ from saleor.site import AuthenticationBackends
from saleor.site.models import AuthorizationKey, SiteSettings
+def pytest_configure(config):
+ """ Remove test files which may have stayed after running tests before. """
+
+ rmtree(django_settings.MEDIA_ROOT, ignore_errors=True)
+
+
+def pytest_unconfigure(config):
+ """ Remove test files after running all tests. """
+
+ rmtree(django_settings.MEDIA_ROOT, ignore_errors=True)
+
+
@pytest.fixture(autouse=True)
def site_settings(db, settings):
"""Create a site and matching site settings.
diff --git a/tests/settings.py b/tests/settings.py
index 105aff1d88..e95956f7de 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -32,3 +32,5 @@ CHECKOUT_PAYMENT_GATEWAYS = {
}
COUNTRIES_ONLY = None
+
+MEDIA_ROOT = os.path.join(MEDIA_ROOT, 'test')