to check that a module’s docstrings are up-to-date by verifying that all interactive examples still work as documented.
to perform regression testing by verifying that interactive examples from a test file or a test object work as expected.
to write tutorial documentation for a package, liberally illustrated with input-output examples. Depending on whether the examples or the expository text are emphasized, this has the flavor of “literate testing” or “executable documentation”.
see factorial.py in utility package for doctest example¶