Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can do this by adding/editing the suite() function in tests.py which defines what tests will be run by the django test runner.</p> <pre><code>import unittest import doctest from project import views def suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(views)) return suite </code></pre> <p>Then just run your tests as usual and you should see your doctests in views.py run.</p> <pre><code>$ python manage.py test project </code></pre> <p>This is described in more detail in the <a href="http://docs.djangoproject.com/en/1.2/topics/testing/" rel="noreferrer">django testing documentation</a></p> <blockquote> <p>When you run your tests, the default behavior of the test utility is to find all the test cases (that is, subclasses of unittest.TestCase) in models.py and tests.py, automatically build a test suite out of those test cases, and run that suite.</p> <p>There is a second way to define the test suite for a module: if you define a function called suite() in either models.py or tests.py, the Django test runner will use that function to construct the test suite for that module. This follows the suggested organization for unit tests. See the Python documentation for more details on how to construct a complex test suite.</p> </blockquote> <p>However, keep in mind that constructing your own test suite means that the django test runner will not automatically run any tests you have in tests.py. You'll have to add these into your suite manually, for example</p> <pre><code>import unittest import doctest from project import views class FooTestCase(unittest.TestCase): def testFoo(self): self.assertEquals('foo', 'bar') def suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(views)) suite.addTest(unittest.TestLoader().loadTestsFromTestCase(FooTestCase)) return suite </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload