Fixed #21281 -- Made override_settings act at class level when used as a TestCase decorator.

This commit is contained in:
Thomas Chaumeny 2014-10-18 20:03:10 +02:00 committed by Tim Graham
parent 8b77b64f1c
commit d89f56dc4d
9 changed files with 73 additions and 27 deletions

View file

@ -607,6 +607,25 @@ then you should use :class:`~django.test.TransactionTestCase` or
``SimpleTestCase`` inherits from ``unittest.TestCase``.
.. warning::
``SimpleTestCase`` and its subclasses (e.g. ``TestCase``, ...) rely on
``setUpClass()`` and ``tearDownClass()`` to perform some class-wide
initialization (e.g. overriding settings). If you need to override those
methods, don't forget to call the ``super`` implementation::
class MyTestCase(TestCase):
@classmethod
def setUpClass(cls):
super(cls, MyTestCase).setUpClass() # Call parent first
...
@classmethod
def tearDownClass(cls):
...
super(cls, MyTestCase).tearDownClass() # Call parent last
TransactionTestCase
~~~~~~~~~~~~~~~~~~~
@ -751,8 +770,8 @@ Then, add a ``LiveServerTestCase``-based test to your app's tests module
@classmethod
def setUpClass(cls):
cls.selenium = WebDriver()
super(MySeleniumTests, cls).setUpClass()
cls.selenium = WebDriver()
@classmethod
def tearDownClass(cls):