On this page
doctest.DocTestFinder
Prev: doctest.DocTestFailure | Up: doctest | Next: doctest.DocTestParser
Rel: doctest.debug, doctest.debug_src, doctest.DebugRunner, doctest.DocFileSuite
Ref: docs.python.org — doctest.DocTestFinder
Tags: #public #python3 #stdlib #doctest
Import
import doctest
from doctest import DocTestFinder
Signature & Overview
doctest.DocTestFinder(verbose=False, parser=<doctest.DocTestParser object at 0x109e84050>, recurse=True, exclude_empty=True)
A class used to extract the DocTests that are relevant to a given object, from its docstring and the docstrings of its contained objects. Doctests can currently be extracted from the following
Methods & Attributes
DocTestFinder.find(self, obj, name=None, module=None, globs=None, extraglobs=None)— Return a list of the DocTests that are defined by the given object's docstring, or by any of its contained objects' docstrings.
Usage
import doctest
def add(a, b):
"""
>>> add(2, 3)
5
"""
return a + b
tests = doctest.DocTestFinder().find(add)
assert len(tests) == 1 and len(tests[0].examples) == 1
Gotchas
- Recursively inspects modules, classes, and functions for
>>>examples.
REPL Inspect
from doctest import DocTestFinder
help(DocTestFinder)
Linked from
Related notes
- tuts/python3/stdlib_module/doctest/DocTestFailure Linked here; links to this page; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocTestParser Linked here; links to this page; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/debug Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/debug_src Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DebugRunner Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocFileSuite Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocTest Linked here; shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/doctest/DocTestRunner shared tags: #doctest, #stdlib
- tuts/python3/stdlib_module/doctest/DocTestSuite shared tags: #doctest, #stdlib