summaryrefslogtreecommitdiff
path: root/tests/staticfiles_tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-12-31 10:01:31 +0100
committerGitHub <noreply@github.com>2023-12-31 10:01:31 +0100
commitd88ec42bd0a37340c8477a6f20bf26e58bd84735 (patch)
treeabd9422f7fb34a19579a74515ce84d9f472cd226 /tests/staticfiles_tests
parent81ccf92f154c6d9eac3e30bac0aa67574d0ace15 (diff)
Used addCleanup() in tests where appropriate.
Diffstat (limited to 'tests/staticfiles_tests')
-rw-r--r--tests/staticfiles_tests/cases.py9
-rw-r--r--tests/staticfiles_tests/test_management.py10
-rw-r--r--tests/staticfiles_tests/test_storage.py22
3 files changed, 15 insertions, 26 deletions
diff --git a/tests/staticfiles_tests/cases.py b/tests/staticfiles_tests/cases.py
index 5e8b150b33..a4816bc09a 100644
--- a/tests/staticfiles_tests/cases.py
+++ b/tests/staticfiles_tests/cases.py
@@ -71,16 +71,13 @@ class CollectionTestCase(BaseStaticFilesMixin, SimpleTestCase):
temp_dir = self.mkdtemp()
# Override the STATIC_ROOT for all tests from setUp to tearDown
# rather than as a context manager
- self.patched_settings = self.settings(STATIC_ROOT=temp_dir)
- self.patched_settings.enable()
+ patched_settings = self.settings(STATIC_ROOT=temp_dir)
+ patched_settings.enable()
if self.run_collectstatic_in_setUp:
self.run_collectstatic()
# Same comment as in runtests.teardown.
self.addCleanup(shutil.rmtree, temp_dir)
-
- def tearDown(self):
- self.patched_settings.disable()
- super().tearDown()
+ self.addCleanup(patched_settings.disable)
def mkdtemp(self):
return tempfile.mkdtemp()
diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py
index 46e6f3e764..c0d3817383 100644
--- a/tests/staticfiles_tests/test_management.py
+++ b/tests/staticfiles_tests/test_management.py
@@ -468,18 +468,14 @@ class TestCollectionFilesOverride(CollectionTestCase):
os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1))
- self.settings_with_test_app = self.modify_settings(
+ settings_with_test_app = self.modify_settings(
INSTALLED_APPS={"prepend": "staticfiles_test_app"},
)
with extend_sys_path(self.temp_dir):
- self.settings_with_test_app.enable()
-
+ settings_with_test_app.enable()
+ self.addCleanup(settings_with_test_app.disable)
super().setUp()
- def tearDown(self):
- super().tearDown()
- self.settings_with_test_app.disable()
-
def test_ordering_override(self):
"""
Test if collectstatic takes files in proper order
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index ea2293ccde..1e537dfe54 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -417,16 +417,15 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase):
with open(self._clear_filename, "w") as f:
f.write("to be deleted in one test")
- self.patched_settings = self.settings(
+ patched_settings = self.settings(
STATICFILES_DIRS=settings.STATICFILES_DIRS + [temp_dir],
)
- self.patched_settings.enable()
+ patched_settings.enable()
+ self.addCleanup(patched_settings.disable)
self.addCleanup(shutil.rmtree, temp_dir)
self._manifest_strict = storage.staticfiles_storage.manifest_strict
def tearDown(self):
- self.patched_settings.disable()
-
if os.path.exists(self._clear_filename):
os.unlink(self._clear_filename)
@@ -702,13 +701,13 @@ class CustomManifestStorage(storage.ManifestStaticFilesStorage):
class TestCustomManifestStorage(SimpleTestCase):
def setUp(self):
- self.manifest_path = Path(tempfile.mkdtemp())
- self.addCleanup(shutil.rmtree, self.manifest_path)
+ manifest_path = Path(tempfile.mkdtemp())
+ self.addCleanup(shutil.rmtree, manifest_path)
self.staticfiles_storage = CustomManifestStorage(
- manifest_location=self.manifest_path,
+ manifest_location=manifest_path,
)
- self.manifest_file = self.manifest_path / self.staticfiles_storage.manifest_name
+ self.manifest_file = manifest_path / self.staticfiles_storage.manifest_name
# Manifest without paths.
self.manifest = {"version": self.staticfiles_storage.manifest_version}
with self.manifest_file.open("w") as manifest_file:
@@ -762,13 +761,10 @@ class TestStaticFilePermissions(CollectionTestCase):
def setUp(self):
self.umask = 0o027
- self.old_umask = os.umask(self.umask)
+ old_umask = os.umask(self.umask)
+ self.addCleanup(os.umask, old_umask)
super().setUp()
- def tearDown(self):
- os.umask(self.old_umask)
- super().tearDown()
-
# Don't run collectstatic command in this test class.
def run_collectstatic(self, **kwargs):
pass