In normal use, end each module M with:
import doctest, M # replace M with your module's name
return doctest.testmod(M) # ditto
if __name__ == "__main__":
If you want to test the module as the main module, you don't need to pass M to testmod(); in this case, it will test the current module.
Then running the module as a script causes the examples in the docstrings to get executed
This won't display anything unless an example fails, in which case the failing example(s)
and the cause(s) of the failure(s) are printed to stdout, and the final line of output is
Run it with the -v switch instead:
and a detailed report of all examples tried is printed to standard output, along with
assorted summaries at the end.
You can force verbose mode by passing
verbose=1 to testmod(),
or prohibit it by passing
verbose=0. In either of those cases,
is not examined by testmod().
In any case, testmod() returns a 2-tuple of ints
t), where f is the number of docstring examples that failed and t
is the total number of docstring examples attempted.