Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a851483

Browse files
committed
#8564: update docs on integrating doctest/unittest with unittest(2) test discovery.
1 parent 1c616a5 commit a851483

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

Doc/library/doctest.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -913,18 +913,16 @@ Unittest API
913913
As your collection of doctest'ed modules grows, you'll want a way to run all
914914
their doctests systematically. :mod:`doctest` provides two functions that can
915915
be used to create :mod:`unittest` test suites from modules and text files
916-
containing doctests. These test suites can then be run using :mod:`unittest`
917-
test runners::
916+
containing doctests. To integrate with :mod:`unittest` test discovery, include
917+
a :func:`load_tests` function in your test module::
918918

919919
import unittest
920920
import doctest
921-
import my_module_with_doctests, and_another
921+
import my_module_with_doctests
922922

923-
suite = unittest.TestSuite()
924-
for mod in my_module_with_doctests, and_another:
925-
suite.addTest(doctest.DocTestSuite(mod))
926-
runner = unittest.TextTestRunner()
927-
runner.run(suite)
923+
def load_tests(loader, tests, ignore):
924+
tests.addTests(doctest.DocTestSuite(my_module_with_doctests))
925+
return test
928926

929927
There are two main functions for creating :class:`unittest.TestSuite` instances
930928
from text files and modules with doctests:

0 commit comments

Comments
 (0)