summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorThomas Chaumeny <t.chaumeny@gmail.com>2014-10-18 20:03:10 +0200
committerTim Graham <timograham@gmail.com>2014-11-03 14:14:39 -0500
commitd89f56dc4d03f6bf6602536b8b62602ec0d46d2f (patch)
treeee089210ebb576d286abbe2bee51db042ee6ee48 /docs
parent8b77b64f1cf878b100d1d2001c8a73938ea3e1ed (diff)
Fixed #21281 -- Made override_settings act at class level when used as a TestCase decorator.
Diffstat (limited to 'docs')
-rw-r--r--docs/releases/1.8.txt8
-rw-r--r--docs/topics/testing/tools.txt21
2 files changed, 28 insertions, 1 deletions
diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt
index 00a2c9844c..875f17f40f 100644
--- a/docs/releases/1.8.txt
+++ b/docs/releases/1.8.txt
@@ -919,3 +919,11 @@ to construct the "view on site" URL. This URL is now accessible using the
``FormMixin`` subclasses that override the ``get_form()`` method should make
sure to provide a default value for the ``form_class`` argument since it's
now optional.
+
+Overriding ``setUpClass`` / ``tearDownClass`` in test cases
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The decorators :func:`~django.test.override_settings` and
+:func:`~django.test.modify_settings` now act at the class level when used as
+class decorators. As a consequence, when overriding ``setUpClass()`` or
+``tearDownClass()``, the ``super`` implementation should always be called.
diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt
index 8049d62761..1ff0d15352 100644
--- a/docs/topics/testing/tools.txt
+++ b/docs/topics/testing/tools.txt
@@ -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):