Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Russell Keith-Magee authored
23  django/test/utils.py
@@ -196,13 +196,22 @@ def __exit__(self, exc_type, exc_value, traceback):
196 196
     def __call__(self, test_func):
197 197
         from django.test import TransactionTestCase
198 198
         if isinstance(test_func, type) and issubclass(test_func, TransactionTestCase):
199  
-            class inner(test_func):
200  
-                def _pre_setup(innerself):
201  
-                    self.enable()
202  
-                    super(inner, innerself)._pre_setup()
203  
-                def _post_teardown(innerself):
204  
-                    super(inner, innerself)._post_teardown()
205  
-                    self.disable()
  199
+            # When decorating a class, we need to construct a new class
  200
+            # with the same name so that the test discovery tools can
  201
+            # get a useful name.
  202
+            def _pre_setup(innerself):
  203
+                self.enable()
  204
+                test_func._pre_setup(innerself)
  205
+            def _post_teardown(innerself):
  206
+                test_func._post_teardown(innerself)
  207
+                self.disable()
  208
+            inner = type(
  209
+                test_func.__name__,
  210
+                (test_func,),
  211
+                {
  212
+                    '_pre_setup': _pre_setup,
  213
+                    '_post_teardown': _post_teardown,
  214
+                })
206 215
         else:
207 216
             @wraps(test_func)
208 217
             def inner(*args, **kwargs):
3  tests/regressiontests/settings_tests/tests.py
@@ -15,6 +15,9 @@ def test_override(self):
15 15
     def test_method_override(self):
16 16
         self.assertEqual(settings.TEST, 'override2')
17 17
 
  18
+    def test_decorated_testcase_name(self):
  19
+        self.assertEquals(FullyDecoratedTranTestCase.__name__, 'FullyDecoratedTranTestCase')
  20
+
18 21
 FullyDecoratedTranTestCase = override_settings(TEST='override')(FullyDecoratedTranTestCase)
19 22
 
20 23
 # @override_settings(TEST='override')

0 notes on commit 0f767f9

Please sign in to comment.
Something went wrong with that request. Please try again.