Ticket #17312: 17312.diff

File 17312.diff, 2.1 KB (added by Tim Graham, 12 years ago)
  • docs/topics/testing.txt

    diff --git a/docs/topics/testing.txt b/docs/topics/testing.txt
    index 8c11e32..2b193e3 100644
    a b Here is an example :class:`unittest.TestCase` subclass::  
    115115
    116116    class AnimalTestCase(unittest.TestCase):
    117117        def setUp(self):
    118             self.lion = Animal.objects.create(name="lion", sound="roar")
    119             self.cat = Animal.objects.create(name="cat", sound="meow")
     118            self.lion = Animal(name="lion", sound="roar")
     119            self.cat = Animal(name="cat", sound="meow")
    120120
    121121        def test_animals_can_speak(self):
    122122            """Animals that can speak are correctly identified"""
    For more details about :mod:`unittest`, see the Python documentation.  
    139139
    140140.. _suggested organization: http://docs.python.org/library/unittest.html#organizing-tests
    141141
     142.. warning::
     143
     144    If your tests rely on database access such as creating or querying models,
     145    be sure to create your test classes as subclasses of
     146    :class:`django.test.TestCase` rather than :class:`unittest.TestCase`.
     147
     148    In the example above, we instantiate some models but do not save them to
     149    the database. Using :class:`unittest.TestCase` avoids the cost of running
     150    each test in a transaction and flushing the database, but for most
     151    applications the scope of tests you will be able to write this way will
     152    be fairly limited, so it's easiest to use :class:`django.test.TestCase`.
     153
    142154Writing doctests
    143155----------------
    144156
    This convenience method sets up the test database, and puts other  
    343355Django features into modes that allow for repeatable testing.
    344356
    345357The call to :meth:`~django.test.utils.setup_test_environment` is made
    346 automatically as part of the setup of `./manage.py test`. You only
     358automatically as part of the setup of ``./manage.py test``. You only
    347359need to manually invoke this method if you're not using running your
    348360tests via Django's test runner.
    349361
    attribute::  
    13851397
    13861398        def test_my_stuff(self):
    13871399            # Here self.client is an instance of MyTestClient...
     1400            call_some_test_code()
    13881401
    13891402.. _topics-testing-fixtures:
    13901403
Back to Top