diff --git a/django/test/testcases.py b/django/test/testcases.py
index 1239275..f4c1569 100644
a
|
b
|
class _AssertTemplateNotUsedContext(_AssertTemplateUsedContext):
|
241 | 241 | |
242 | 242 | |
243 | 243 | class SimpleTestCase(ut2.TestCase): |
| 244 | def __call__(self, result=None): |
| 245 | """ |
| 246 | Wrapper around default __call__ method to perform common Django test |
| 247 | set up. This means that user-defined Test Cases aren't required to |
| 248 | include a call to super().setUp(). |
| 249 | """ |
| 250 | testMethod = getattr(self, self._testMethodName) |
| 251 | skipped = (getattr(self.__class__, "__unittest_skip__", False) or |
| 252 | getattr(testMethod, "__unittest_skip__", False)) |
| 253 | |
| 254 | if not skipped: |
| 255 | try: |
| 256 | self._pre_setup() |
| 257 | except (KeyboardInterrupt, SystemExit): |
| 258 | raise |
| 259 | except Exception: |
| 260 | result.addError(self, sys.exc_info()) |
| 261 | return |
| 262 | super(SimpleTestCase, self).__call__(result) |
| 263 | if not skipped: |
| 264 | try: |
| 265 | self._post_teardown() |
| 266 | except (KeyboardInterrupt, SystemExit): |
| 267 | raise |
| 268 | except Exception: |
| 269 | result.addError(self, sys.exc_info()) |
| 270 | return |
| 271 | |
| 272 | def _pre_setup(self): |
| 273 | pass |
| 274 | |
| 275 | def _post_teardown(self): |
| 276 | pass |
| 277 | |
244 | 278 | def save_warnings_state(self): |
245 | 279 | """ |
246 | 280 | Saves the state of the warnings module |
… |
… |
class TransactionTestCase(SimpleTestCase):
|
412 | 446 | ROOT_URLCONF with it. |
413 | 447 | * Clearing the mail test outbox. |
414 | 448 | """ |
| 449 | self.client = self.client_class() |
415 | 450 | self._fixture_setup() |
416 | 451 | self._urlconf_setup() |
417 | 452 | mail.outbox = [] |
… |
… |
class TransactionTestCase(SimpleTestCase):
|
453 | 488 | settings.ROOT_URLCONF = self.urls |
454 | 489 | clear_url_caches() |
455 | 490 | |
456 | | def __call__(self, result=None): |
457 | | """ |
458 | | Wrapper around default __call__ method to perform common Django test |
459 | | set up. This means that user-defined Test Cases aren't required to |
460 | | include a call to super().setUp(). |
461 | | """ |
462 | | testMethod = getattr(self, self._testMethodName) |
463 | | skipped = (getattr(self.__class__, "__unittest_skip__", False) or |
464 | | getattr(testMethod, "__unittest_skip__", False)) |
465 | | |
466 | | if not skipped: |
467 | | self.client = self.client_class() |
468 | | try: |
469 | | self._pre_setup() |
470 | | except (KeyboardInterrupt, SystemExit): |
471 | | raise |
472 | | except Exception: |
473 | | result.addError(self, sys.exc_info()) |
474 | | return |
475 | | super(TransactionTestCase, self).__call__(result) |
476 | | if not skipped: |
477 | | try: |
478 | | self._post_teardown() |
479 | | except (KeyboardInterrupt, SystemExit): |
480 | | raise |
481 | | except Exception: |
482 | | result.addError(self, sys.exc_info()) |
483 | | return |
484 | | |
485 | 491 | def _post_teardown(self): |
486 | 492 | """ Performs any post-test things. This includes: |
487 | 493 | |
diff --git a/django/test/utils.py b/django/test/utils.py
index f10d388..8114ae0 100644
a
|
b
|
class override_settings(object):
|
187 | 187 | self.disable() |
188 | 188 | |
189 | 189 | def __call__(self, test_func): |
190 | | from django.test import TransactionTestCase |
191 | | if isinstance(test_func, type) and issubclass(test_func, TransactionTestCase): |
| 190 | from django.test import SimpleTestCase |
| 191 | if isinstance(test_func, type): |
| 192 | if not issubclass(test_func, SimpleTestCase): |
| 193 | raise Exception( |
| 194 | "Only subclasses of Django SimpleTestCase can be decorated " |
| 195 | "with override_settings") |
192 | 196 | original_pre_setup = test_func._pre_setup |
193 | 197 | original_post_teardown = test_func._post_teardown |
194 | 198 | |
diff --git a/tests/regressiontests/settings_tests/tests.py b/tests/regressiontests/settings_tests/tests.py
index aaf8bcf..68f620b 100644
a
|
b
|
import warnings
|
4 | 4 | from django.conf import settings, global_settings |
5 | 5 | from django.core.exceptions import ImproperlyConfigured |
6 | 6 | from django.http import HttpRequest |
7 | | from django.test import TransactionTestCase, TestCase, signals |
| 7 | from django.test import SimpleTestCase, TransactionTestCase, TestCase, signals |
8 | 8 | from django.test.utils import override_settings |
| 9 | from django.utils import unittest, six |
9 | 10 | |
10 | 11 | |
11 | 12 | @override_settings(TEST='override') |
… |
… |
class ClassDecoratedTestCase(ClassDecoratedTestCaseSuper):
|
67 | 68 | self.fail() |
68 | 69 | |
69 | 70 | |
70 | | class SettingGetter(object): |
71 | | def __init__(self): |
72 | | self.test = getattr(settings, 'TEST', 'undefined') |
73 | | |
74 | | |
75 | 71 | class SettingsTests(TestCase): |
76 | 72 | def setUp(self): |
77 | 73 | self.testvalue = None |
… |
… |
class SettingsTests(TestCase):
|
122 | 118 | self.assertRaises(AttributeError, getattr, settings, 'TEST') |
123 | 119 | |
124 | 120 | def test_class_decorator(self): |
125 | | self.assertEqual(SettingGetter().test, 'undefined') |
126 | | DecoratedSettingGetter = override_settings(TEST='override')(SettingGetter) |
127 | | self.assertEqual(DecoratedSettingGetter().test, 'override') |
128 | | self.assertRaises(AttributeError, getattr, settings, 'TEST') |
| 121 | # SimpleTestCase can be decorated by override_settings, but not ut.TestCase |
| 122 | class SimpleTestCaseSubclass(SimpleTestCase): |
| 123 | pass |
| 124 | |
| 125 | class UnittestTestCaseSubclass(unittest.TestCase): |
| 126 | pass |
| 127 | |
| 128 | decorated = override_settings(TEST='override')(SimpleTestCaseSubclass) |
| 129 | self.assertIsInstance(decorated, type) |
| 130 | self.assertTrue(issubclass(decorated, SimpleTestCase)) |
| 131 | |
| 132 | with six.assertRaisesRegex(self, Exception, |
| 133 | "Only subclasses of Django SimpleTestCase*"): |
| 134 | decorated = override_settings(TEST='override')(UnittestTestCaseSubclass) |
129 | 135 | |
130 | 136 | def test_signal_callback_context_manager(self): |
131 | 137 | self.assertRaises(AttributeError, getattr, settings, 'TEST') |