summaryrefslogtreecommitdiff
path: root/django/test/utils.py
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2011-06-11 20:40:02 +0000
committerJannis Leidel <jannis@leidel.info>2011-06-11 20:40:02 +0000
commita0791b2759b475fda9ffea31154d5e436ffdd00f (patch)
tree1434d1293536291804139f17f0f655ecdd78a220 /django/test/utils.py
parente096d56406b93220f03c495282fd6d0d297f3851 (diff)
downloaddjango-a0791b2759b475fda9ffea31154d5e436ffdd00f.tar.gz
Fixed #16224 -- Fixed override_settings test utility to correctly work with TestCase classes.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@16377 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/test/utils.py')
-rw-r--r--django/test/utils.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/django/test/utils.py b/django/test/utils.py
index b9f4743a34..19a3190166 100644
--- a/django/test/utils.py
+++ b/django/test/utils.py
@@ -197,11 +197,21 @@ class override_settings(object):
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):