Permalink
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...
1 parent b9244cf commit 0f767f9a993f5834f7a2004bf4c440a126a73d06 @freakboy3742 freakboy3742 committed Aug 23, 2011
Showing with 19 additions and 7 deletions.
  1. +16 −7 django/test/utils.py
  2. +3 −0 tests/regressiontests/settings_tests/tests.py
View
@@ -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):
@@ -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')

0 comments on commit 0f767f9

Please sign in to comment.