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
This commit is contained in:
parent
b9244cfb89
commit
0f767f9a99
|
@ -196,13 +196,22 @@ class override_settings(object):
|
||||||
def __call__(self, test_func):
|
def __call__(self, test_func):
|
||||||
from django.test import TransactionTestCase
|
from django.test import TransactionTestCase
|
||||||
if isinstance(test_func, type) and issubclass(test_func, 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
|
||||||
def _pre_setup(innerself):
|
# with the same name so that the test discovery tools can
|
||||||
self.enable()
|
# get a useful name.
|
||||||
super(inner, innerself)._pre_setup()
|
def _pre_setup(innerself):
|
||||||
def _post_teardown(innerself):
|
self.enable()
|
||||||
super(inner, innerself)._post_teardown()
|
test_func._pre_setup(innerself)
|
||||||
self.disable()
|
def _post_teardown(innerself):
|
||||||
|
test_func._post_teardown(innerself)
|
||||||
|
self.disable()
|
||||||
|
inner = type(
|
||||||
|
test_func.__name__,
|
||||||
|
(test_func,),
|
||||||
|
{
|
||||||
|
'_pre_setup': _pre_setup,
|
||||||
|
'_post_teardown': _post_teardown,
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
@wraps(test_func)
|
@wraps(test_func)
|
||||||
def inner(*args, **kwargs):
|
def inner(*args, **kwargs):
|
||||||
|
|
|
@ -15,6 +15,9 @@ class FullyDecoratedTranTestCase(TransactionTestCase):
|
||||||
def test_method_override(self):
|
def test_method_override(self):
|
||||||
self.assertEqual(settings.TEST, 'override2')
|
self.assertEqual(settings.TEST, 'override2')
|
||||||
|
|
||||||
|
def test_decorated_testcase_name(self):
|
||||||
|
self.assertEquals(FullyDecoratedTranTestCase.__name__, 'FullyDecoratedTranTestCase')
|
||||||
|
|
||||||
FullyDecoratedTranTestCase = override_settings(TEST='override')(FullyDecoratedTranTestCase)
|
FullyDecoratedTranTestCase = override_settings(TEST='override')(FullyDecoratedTranTestCase)
|
||||||
|
|
||||||
# @override_settings(TEST='override')
|
# @override_settings(TEST='override')
|
||||||
|
|
Loading…
Reference in New Issue