diff options
author | Chris Jerdonek <chris.jerdonek@gmail.com> | 2021-02-15 10:15:06 +0100 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-02-15 10:23:54 +0100 |
commit | fc0069bfa52f9d8bd62aa0f5749905d767ab42e9 (patch) | |
tree | 582078ee42a8f6d4c9f7ab15f3c8a75b6b8aef46 /tests/staticfiles_tests | |
parent | 3fa1ed53be370f4b1a94d78b56ff30d23b131623 (diff) | |
download | django-fc0069bfa52f9d8bd62aa0f5749905d767ab42e9.tar.gz |
Refs #32417 -- Improved cleaning up and fixed isolation of staticfiles_tests tests.
Diffstat (limited to 'tests/staticfiles_tests')
-rw-r--r-- | tests/staticfiles_tests/test_liveserver.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/tests/staticfiles_tests/test_liveserver.py b/tests/staticfiles_tests/test_liveserver.py index eb027f7341..970121f2da 100644 --- a/tests/staticfiles_tests/test_liveserver.py +++ b/tests/staticfiles_tests/test_liveserver.py @@ -29,14 +29,23 @@ class LiveServerBase(StaticLiveServerTestCase): # Override settings cls.settings_override = override_settings(**TEST_SETTINGS) cls.settings_override.enable() - super().setUpClass() + try: + super().setUpClass() + except Exception: + # Clean up since tearDownClass() isn't called on errors. + cls._tearDownLiveServerBase() + raise @classmethod - def tearDownClass(cls): - super().tearDownClass() + def _tearDownLiveServerBase(cls): # Restore original settings cls.settings_override.disable() + @classmethod + def tearDownClass(cls): + super().tearDownClass() + cls._tearDownLiveServerBase() + class StaticLiveServerChecks(LiveServerBase): @@ -46,8 +55,10 @@ class StaticLiveServerChecks(LiveServerBase): # should bubble up to the main thread. old_STATIC_URL = TEST_SETTINGS['STATIC_URL'] TEST_SETTINGS['STATIC_URL'] = None - cls.raises_exception() - TEST_SETTINGS['STATIC_URL'] = old_STATIC_URL + try: + cls.raises_exception() + finally: + TEST_SETTINGS['STATIC_URL'] = old_STATIC_URL @classmethod def tearDownClass(cls): @@ -58,16 +69,14 @@ class StaticLiveServerChecks(LiveServerBase): def raises_exception(cls): try: super().setUpClass() - raise Exception("The line above should have raised an exception") except ImproperlyConfigured: # This raises ImproperlyConfigured("You're using the staticfiles # app without having set the required STATIC_URL setting.") pass - finally: - # Use del to avoid decrementing the database thread sharing count a - # second time. - del cls.server_thread + else: + # super().setUpClass() cleans up after itself on a failure. super().tearDownClass() + raise Exception('setUpClass() should have raised an exception.') def test_test_test(self): # Intentionally empty method so that the test is picked up by the |