mirror of https://github.com/django/django.git
Refs #32417 -- Improved cleaning up and fixed isolation of staticfiles_tests tests.
This commit is contained in:
parent
3fa1ed53be
commit
fc0069bfa5
|
@ -29,13 +29,22 @@ 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 _tearDownLiveServerBase(cls):
|
||||
# Restore original settings
|
||||
cls.settings_override.disable()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super().tearDownClass()
|
||||
# Restore original settings
|
||||
cls.settings_override.disable()
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue