]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
#8564: update docs on integrating doctest/unittest with unittest(2) test discovery.
authorGeorg Brandl <georg@python.org>
Sat, 10 Jul 2010 12:20:38 +0000 (12:20 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 10 Jul 2010 12:20:38 +0000 (12:20 +0000)
Doc/library/doctest.rst

index 4b2a28da6a326eb27802d73a43686f18eafadfa5..420c73ea775879616926f3f323eb260eb4853a05 100644 (file)
@@ -913,18 +913,16 @@ Unittest API
 As your collection of doctest'ed modules grows, you'll want a way to run all
 their doctests systematically.  :mod:`doctest` provides two functions that can
 be used to create :mod:`unittest` test suites from modules and text files
-containing doctests.  These test suites can then be run using :mod:`unittest`
-test runners::
+containing doctests.  To integrate with :mod:`unittest` test discovery, include
+a :func:`load_tests` function in your test module::
 
    import unittest
    import doctest
-   import my_module_with_doctests, and_another
+   import my_module_with_doctests
 
-   suite = unittest.TestSuite()
-   for mod in my_module_with_doctests, and_another:
-       suite.addTest(doctest.DocTestSuite(mod))
-   runner = unittest.TextTestRunner()
-   runner.run(suite)
+   def load_tests(loader, tests, ignore):
+       tests.addTests(doctest.DocTestSuite(my_module_with_doctests))
+       return test
 
 There are two main functions for creating :class:`unittest.TestSuite` instances
 from text files and modules with doctests: