summaryrefslogtreecommitdiffstats
path: root/Doc/library/doctest.rst
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-07-10 12:20:38 (GMT)
committerGeorg Brandl <georg@python.org>2010-07-10 12:20:38 (GMT)
commita85148352773929e11324f3786ebe5a78f372d94 (patch)
tree65397198ad7305045c5259252eefdc971d358677 /Doc/library/doctest.rst
parent1c616a5c92b9d9dee90570edefe708358ed47f45 (diff)
downloadcpython-a85148352773929e11324f3786ebe5a78f372d94.zip
cpython-a85148352773929e11324f3786ebe5a78f372d94.tar.gz
cpython-a85148352773929e11324f3786ebe5a78f372d94.tar.bz2
#8564: update docs on integrating doctest/unittest with unittest(2) test discovery.
Diffstat (limited to 'Doc/library/doctest.rst')
-rw-r--r--Doc/library/doctest.rst14
1 files changed, 6 insertions, 8 deletions
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
index 4b2a28d..420c73e 100644
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -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: