PyMOTW: doctest – Testing through documentation
Originally posted
· 1 min read
doctest
lets you test your code by running examples embedded in the documentation and verifying that they produce the expected results. It works by parsing the help text to find examples, running them, then comparing the output text against the expected value. Many developers find doctest
easier than unittest
because in its simplest form, there is no API to learn before using it. However, as the examples become more complex the lack of fixture management can make writing doctest
tests more cumbersome than using unittest
.