Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #16224 -- Fixed override_settings test utility to correctly wor…

…k with TestCase classes.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16377 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a0791b2759b475fda9ffea31154d5e436ffdd00f 1 parent e096d56
Jannis Leidel authored June 11, 2011
20  django/test/utils.py
@@ -197,11 +197,21 @@ def __enter__(self):
197 197
     def __exit__(self, exc_type, exc_value, traceback):
198 198
         self.disable()
199 199
 
200  
-    def __call__(self, func):
201  
-        @wraps(func)
202  
-        def inner(*args, **kwargs):
203  
-            with self:
204  
-                return func(*args, **kwargs)
  200
+    def __call__(self, test_func):
  201
+        from django.test import TestCase
  202
+        if isinstance(test_func, type) and issubclass(test_func, TestCase):
  203
+            class inner(test_func):
  204
+                def _pre_setup(innerself):
  205
+                    self.enable()
  206
+                    super(inner, innerself)._pre_setup()
  207
+                def _post_teardown(innerself):
  208
+                    super(inner, innerself)._post_teardown()
  209
+                    self.disable()
  210
+        else:
  211
+            @wraps(test_func)
  212
+            def inner(*args, **kwargs):
  213
+                with self:
  214
+                    return test_func(*args, **kwargs)
205 215
         return inner
206 216
 
207 217
     def enable(self):
15  tests/regressiontests/settings_tests/tests.py
... ...
@@ -1,11 +1,22 @@
1 1
 from __future__ import with_statement
2  
-import os, sys
  2
+import os
3 3
 from django.conf import settings, global_settings
4 4
 from django.test import TestCase, signals
5 5
 from django.test.utils import override_settings
6  
-from django.utils.unittest import skipIf
7 6
 
8 7
 
  8
+# @override_settings(TEST='override')
  9
+class FullyDecoratedTestCase(TestCase):
  10
+
  11
+    def test_override(self):
  12
+        self.assertEqual(settings.TEST, 'override')
  13
+
  14
+    @override_settings(TEST='override2')
  15
+    def test_method_override(self):
  16
+        self.assertEqual(settings.TEST, 'override2')
  17
+
  18
+FullyDecoratedTestCase = override_settings(TEST='override')(FullyDecoratedTestCase)
  19
+
9 20
 class SettingGetter(object):
10 21
     def __init__(self):
11 22
         self.test = getattr(settings, 'TEST', 'undefined')

0 notes on commit a0791b2

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