Code

Ticket #17312: 17312.diff

File 17312.diff, 2.1 KB (added by timo, 16 months ago)
Line 
1diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
2index 8c11e32..2b193e3 100644
3--- a/docs/topics/testing.txt
4+++ b/docs/topics/testing.txt
5@@ -115,8 +115,8 @@ Here is an example :class:`unittest.TestCase` subclass::
6 
7     class AnimalTestCase(unittest.TestCase):
8         def setUp(self):
9-            self.lion = Animal.objects.create(name="lion", sound="roar")
10-            self.cat = Animal.objects.create(name="cat", sound="meow")
11+            self.lion = Animal(name="lion", sound="roar")
12+            self.cat = Animal(name="cat", sound="meow")
13 
14         def test_animals_can_speak(self):
15             """Animals that can speak are correctly identified"""
16@@ -139,6 +139,18 @@ For more details about :mod:`unittest`, see the Python documentation.
17 
18 .. _suggested organization: http://docs.python.org/library/unittest.html#organizing-tests
19 
20+.. warning::
21+
22+    If your tests rely on database access such as creating or querying models,
23+    be sure to create your test classes as subclasses of
24+    :class:`django.test.TestCase` rather than :class:`unittest.TestCase`.
25+
26+    In the example above, we instantiate some models but do not save them to
27+    the database. Using :class:`unittest.TestCase` avoids the cost of running
28+    each test in a transaction and flushing the database, but for most
29+    applications the scope of tests you will be able to write this way will
30+    be fairly limited, so it's easiest to use :class:`django.test.TestCase`.
31+
32 Writing doctests
33 ----------------
34 
35@@ -343,7 +355,7 @@ This convenience method sets up the test database, and puts other
36 Django features into modes that allow for repeatable testing.
37 
38 The call to :meth:`~django.test.utils.setup_test_environment` is made
39-automatically as part of the setup of `./manage.py test`. You only
40+automatically as part of the setup of ``./manage.py test``. You only
41 need to manually invoke this method if you're not using running your
42 tests via Django's test runner.
43 
44@@ -1385,6 +1397,7 @@ attribute::
45 
46         def test_my_stuff(self):
47             # Here self.client is an instance of MyTestClient...
48+            call_some_test_code()
49 
50 .. _topics-testing-fixtures:
51