Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@jezdez jezdez authored
View
20 django/test/utils.py
@@ -197,11 +197,21 @@ def __enter__(self):
def __exit__(self, exc_type, exc_value, traceback):
self.disable()
- def __call__(self, func):
- @wraps(func)
- def inner(*args, **kwargs):
- with self:
- return func(*args, **kwargs)
+ def __call__(self, test_func):
+ from django.test import TestCase
+ if isinstance(test_func, type) and issubclass(test_func, TestCase):
+ 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()
+ else:
+ @wraps(test_func)
+ def inner(*args, **kwargs):
+ with self:
+ return test_func(*args, **kwargs)
return inner
def enable(self):
View
15 tests/regressiontests/settings_tests/tests.py
@@ -1,11 +1,22 @@
from __future__ import with_statement
-import os, sys
+import os
from django.conf import settings, global_settings
from django.test import TestCase, signals
from django.test.utils import override_settings
-from django.utils.unittest import skipIf
+# @override_settings(TEST='override')
+class FullyDecoratedTestCase(TestCase):
+
+ def test_override(self):
+ self.assertEqual(settings.TEST, 'override')
+
+ @override_settings(TEST='override2')
+ def test_method_override(self):
+ self.assertEqual(settings.TEST, 'override2')
+
+FullyDecoratedTestCase = override_settings(TEST='override')(FullyDecoratedTestCase)
+
class SettingGetter(object):
def __init__(self):
self.test = getattr(settings, 'TEST', 'undefined')
Please sign in to comment.
Something went wrong with that request. Please try again.