Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #16672 -- Ensure that test classes decorated with @override_set…

…ings gets the right name when running the tests. Thanks to Julien Phalip for the report and initial patch

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16650 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0f767f9a993f5834f7a2004bf4c440a126a73d06 1 parent b9244cf
@freakboy3742 freakboy3742 authored
View
23 django/test/utils.py
@@ -196,13 +196,22 @@ def __exit__(self, exc_type, exc_value, traceback):
def __call__(self, test_func):
from django.test import TransactionTestCase
if isinstance(test_func, type) and issubclass(test_func, TransactionTestCase):
- class inner(test_func):
- def _pre_setup(innerself):
- self.enable()
- super(inner, innerself)._pre_setup()
- def _post_teardown(innerself):
- super(inner, innerself)._post_teardown()
- self.disable()
+ # When decorating a class, we need to construct a new class
+ # with the same name so that the test discovery tools can
+ # get a useful name.
+ def _pre_setup(innerself):
+ self.enable()
+ test_func._pre_setup(innerself)
+ def _post_teardown(innerself):
+ test_func._post_teardown(innerself)
+ self.disable()
+ inner = type(
+ test_func.__name__,
+ (test_func,),
+ {
+ '_pre_setup': _pre_setup,
+ '_post_teardown': _post_teardown,
+ })
else:
@wraps(test_func)
def inner(*args, **kwargs):
View
3  tests/regressiontests/settings_tests/tests.py
@@ -15,6 +15,9 @@ def test_override(self):
def test_method_override(self):
self.assertEqual(settings.TEST, 'override2')
+ def test_decorated_testcase_name(self):
+ self.assertEquals(FullyDecoratedTranTestCase.__name__, 'FullyDecoratedTranTestCase')
+
FullyDecoratedTranTestCase = override_settings(TEST='override')(FullyDecoratedTranTestCase)
# @override_settings(TEST='override')
Please sign in to comment.
Something went wrong with that request. Please try again.