mirror of
https://github.com/django/django.git
synced 2025-10-25 22:56:12 +00:00
Enabled SimpleTestCase to be decorated by override_settings
Refs #18417. Also fixed some test case classes which subclassed the wrong parent.
This commit is contained in:
@@ -241,6 +241,40 @@ class _AssertTemplateNotUsedContext(_AssertTemplateUsedContext):
|
||||
|
||||
|
||||
class SimpleTestCase(ut2.TestCase):
|
||||
def __call__(self, result=None):
|
||||
"""
|
||||
Wrapper around default __call__ method to perform common Django test
|
||||
set up. This means that user-defined Test Cases aren't required to
|
||||
include a call to super().setUp().
|
||||
"""
|
||||
testMethod = getattr(self, self._testMethodName)
|
||||
skipped = (getattr(self.__class__, "__unittest_skip__", False) or
|
||||
getattr(testMethod, "__unittest_skip__", False))
|
||||
|
||||
if not skipped:
|
||||
try:
|
||||
self._pre_setup()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except Exception:
|
||||
result.addError(self, sys.exc_info())
|
||||
return
|
||||
super(SimpleTestCase, self).__call__(result)
|
||||
if not skipped:
|
||||
try:
|
||||
self._post_teardown()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except Exception:
|
||||
result.addError(self, sys.exc_info())
|
||||
return
|
||||
|
||||
def _pre_setup(self):
|
||||
pass
|
||||
|
||||
def _post_teardown(self):
|
||||
pass
|
||||
|
||||
def save_warnings_state(self):
|
||||
"""
|
||||
Saves the state of the warnings module
|
||||
@@ -412,6 +446,7 @@ class TransactionTestCase(SimpleTestCase):
|
||||
ROOT_URLCONF with it.
|
||||
* Clearing the mail test outbox.
|
||||
"""
|
||||
self.client = self.client_class()
|
||||
self._fixture_setup()
|
||||
self._urlconf_setup()
|
||||
mail.outbox = []
|
||||
@@ -459,35 +494,6 @@ class TransactionTestCase(SimpleTestCase):
|
||||
settings.ROOT_URLCONF = self.urls
|
||||
clear_url_caches()
|
||||
|
||||
def __call__(self, result=None):
|
||||
"""
|
||||
Wrapper around default __call__ method to perform common Django test
|
||||
set up. This means that user-defined Test Cases aren't required to
|
||||
include a call to super().setUp().
|
||||
"""
|
||||
testMethod = getattr(self, self._testMethodName)
|
||||
skipped = (getattr(self.__class__, "__unittest_skip__", False) or
|
||||
getattr(testMethod, "__unittest_skip__", False))
|
||||
|
||||
if not skipped:
|
||||
self.client = self.client_class()
|
||||
try:
|
||||
self._pre_setup()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except Exception:
|
||||
result.addError(self, sys.exc_info())
|
||||
return
|
||||
super(TransactionTestCase, self).__call__(result)
|
||||
if not skipped:
|
||||
try:
|
||||
self._post_teardown()
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except Exception:
|
||||
result.addError(self, sys.exc_info())
|
||||
return
|
||||
|
||||
def _post_teardown(self):
|
||||
""" Performs any post-test things. This includes:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user