Commit 0f767f9a authored by Russell Keith-Magee's avatar Russell Keith-Magee
Browse files

Fixed #16672 -- Ensure that test classes decorated with @override_setings gets...

Fixed #16672 -- Ensure that test classes decorated with @override_setings 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
parent b9244cfb
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -196,13 +196,22 @@ class override_settings(object):
    def __call__(self, test_func):
        from django.test import TransactionTestCase
        if isinstance(test_func, type) and issubclass(test_func, TransactionTestCase):
            class inner(test_func):
            # 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()
                    super(inner, innerself)._pre_setup()
                test_func._pre_setup(innerself)
            def _post_teardown(innerself):
                    super(inner, innerself)._post_teardown()
                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):
+3 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@ class FullyDecoratedTranTestCase(TransactionTestCase):
    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')