summaryrefslogtreecommitdiff
path: root/tests/staticfiles_tests/test_storage.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-06-05 00:02:32 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-09-09 23:01:17 +0200
commitbf2c969eb7d941812993d69bcf7c8ac35bdb7726 (patch)
tree1ae952d9505f1f6e8185563b4a11a63dae5b7914 /tests/staticfiles_tests/test_storage.py
parent326bc0955b2e9ab6b6cfd62263c9b3fe2fb1d333 (diff)
Prevented staticfiles test from colliding when run in parallel.
This requires that each test never alters files in static directories collected by other tests. The alternative is to add a temporary directory to STATICFILES_DIRS or a new app to INSTALLED_APPS.
Diffstat (limited to 'tests/staticfiles_tests/test_storage.py')
-rw-r--r--tests/staticfiles_tests/test_storage.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index c3318512f6..b96d9d0f12 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -1,7 +1,9 @@
from __future__ import unicode_literals
import os
+import shutil
import sys
+import tempfile
import unittest
from django.conf import settings
@@ -18,7 +20,7 @@ from django.utils.encoding import force_text
from .cases import (
BaseCollectionTestCase, BaseStaticFilesTestCase, StaticFilesTestCase,
)
-from .settings import TEST_ROOT, TEST_SETTINGS, TESTFILES_PATH
+from .settings import TEST_ROOT, TEST_SETTINGS
def hashed_file_path(test, path):
@@ -252,15 +254,25 @@ class TestCollectionManifestStorage(TestHashedFiles, BaseCollectionTestCase,
def setUp(self):
super(TestCollectionManifestStorage, self).setUp()
- self._clear_filename = os.path.join(TESTFILES_PATH, 'cleared.txt')
+ temp_dir = tempfile.mkdtemp()
+ os.makedirs(os.path.join(temp_dir, 'test'))
+ self._clear_filename = os.path.join(temp_dir, 'test', 'cleared.txt')
with open(self._clear_filename, 'w') as f:
f.write('to be deleted in one test')
+ self.patched_settings = self.settings(
+ STATICFILES_DIRS=settings.STATICFILES_DIRS + [temp_dir])
+ self.patched_settings.enable()
+ self.addCleanup(shutil.rmtree, six.text_type(temp_dir))
+
def tearDown(self):
- super(TestCollectionManifestStorage, self).tearDown()
+ self.patched_settings.disable()
+
if os.path.exists(self._clear_filename):
os.unlink(self._clear_filename)
+ super(TestCollectionManifestStorage, self).tearDown()
+
def test_manifest_exists(self):
filename = storage.staticfiles_storage.manifest_name
path = storage.staticfiles_storage.path(filename)