See the docstrings in doctest.py for all the details. They're unsurprising: the module docstring, and all function, class and method docstrings are searched. Optionally, the tester can be directed to exclude docstrings attached to objects with private names. Objects imported into the module are not searched.
In addition, if
M.__test__ exists and "is true", it must be a
dict, and each entry maps a (string) name to a function object, class
object, or string. Function and class object docstrings found from
M.__test__ are searched even if the tester has been
directed to skip over private names in the rest of the module.
In output, a key
M.__test__ appears with name
<name of M>.__test__.K
Any classes found are recursively searched similarly, to test docstrings in
their contained methods and nested classes. While private names reached
from M's globals can be optionally skipped, all names reached from
M.__test__ are searched.
See About this document... for information on suggesting changes.