diff --git a/core/tests/runner.py b/core/tests/runner.py new file mode 100644 index 0000000..4faf90a --- /dev/null +++ b/core/tests/runner.py @@ -0,0 +1,18 @@ +import os +import shutil + +from django.test.runner import DiscoverRunner +from django.conf import settings + + +class TempMediaMixin(DiscoverRunner): + + def setup_test_environment(self, **kwargs): + super(TempMediaMixin, self).setup_test_environment() + settings._original_media_root = settings.MEDIA_ROOT + self._temp_media = '/tmp/test/' + settings.MEDIA_ROOT = self._temp_media + + def teardown_test_environment(self, **kwargs): + if os.path.exists('/tmp/test/'): + shutil.rmtree('/tmp/test/') diff --git a/project/settings.py b/project/settings.py index d1475ba..cadd512 100644 --- a/project/settings.py +++ b/project/settings.py @@ -104,6 +104,8 @@ }, ] +TEST_RUNNER = 'core.tests.runner.TempMediaMixin' + # Internationalization # https://docs.djangoproject.com/en/1.11/topics/i18n/