all Python 3doctestterm
doctest.DocTestFinder
building blocks
Finds docstrings with examples on an object and on the functions, classes and methods nested in it, returning a list of DocTest objects.
Syntax
doctest.DocTestFinder(verbose=False, parser=DocTestParser(), recurse=True, exclude_empty=True).find(obj, name=None, module=None, globs=None)
It checks __module__ and skips objects imported from other modules: from utils import f does not make testmod() test f. Objects without a docstring are dropped by default (exclude_empty=True), while a docstring with no examples yields a DocTest with zero examples. Test names are fully qualified: 'Box.area', and for a module they carry the module name.
Examples
import doctest
class Box:
def area(self):
"""
>>> Box().area()
4
"""
return 4
tests = doctest.DocTestFinder().find(Box)
print([t.name for t in tests]) # → ['Box.area']
print([t.name for t in doctest.DocTestFinder(exclude_empty=False).find(Box)]) # → ['Box', 'Box.area']
See also
Open in the full glossarydocs.python.orgReport an inaccuracy