Ticket #18417: 18417-1.diff

File 18417-1.diff, 2.0 KB (added by Claude Paroz, 12 years ago)

Allow unittest.TestCase to be decorated by override_settings

  • django/test/utils.py

    diff --git a/django/test/utils.py b/django/test/utils.py
    index 805117d..7993b47 100644
    a b class override_settings(object):  
    174174    """
    175175    def __init__(self, **kwargs):
    176176        self.options = kwargs
    177         self.wrapped = settings._wrapped
    178177
    179178    def __enter__(self):
    180179        self.enable()
    class override_settings(object):  
    183182        self.disable()
    184183
    185184    def __call__(self, test_func):
    186         from django.test import TransactionTestCase
    187         if isinstance(test_func, type) and issubclass(test_func, TransactionTestCase):
    188             original_pre_setup = test_func._pre_setup
    189             original_post_teardown = test_func._post_teardown
    190             def _pre_setup(innerself):
     185        from django.utils.unittest import TestCase
     186        if isinstance(test_func, type) and issubclass(test_func, TestCase):
     187            original_setUpClass = test_func.setUpClass
     188            original_tearDownClass = test_func.tearDownClass
     189            @classmethod
     190            def setUpClass(cls):
    191191                self.enable()
    192                 original_pre_setup(innerself)
    193             def _post_teardown(innerself):
    194                 original_post_teardown(innerself)
     192                original_setUpClass()
     193            @classmethod
     194            def tearDownClass(cls):
     195                original_tearDownClass()
    195196                self.disable()
    196             test_func._pre_setup = _pre_setup
    197             test_func._post_teardown = _post_teardown
     197            test_func.setUpClass = setUpClass
     198            test_func.tearDownClass = tearDownClass
    198199            return test_func
    199200        else:
    200201            @wraps(test_func)
    class override_settings(object):  
    204205        return inner
    205206
    206207    def enable(self):
     208        self.wrapped = settings._wrapped
    207209        override = UserSettingsHolder(settings._wrapped)
    208210        for key, new_value in self.options.items():
    209211            setattr(override, key, new_value)
Back to Top