In brief
doctest finds text resembling an interactive Python session and checks whether execution produces the displayed output. This keeps small examples connected to the actual interface.
Useful to know
doctest finds text resembling an interactive Python session and checks whether execution produces the displayed output. This keeps small examples connected to the actual interface. [1]
Exact output matters. Variable timing, random values and external-environment dependencies hinder reproduction. Use it for clear demonstrations without treating it as a replacement for every regression check.
Sources
For further detail and to check the information: