Last Updated: February 25, 2016
·
319
· jnuss

Python tests right in your doc strings

I just found out about Python doctest and my mind is blown. This allows you to write tests right in your docstrings. One advantage to this is that your documentation will include working examples of your code. However, if you refactor and change something, your tests will fail rather than having out of date documentation. I certainly wouldn't want to have an extensive set of test cases in my documentation, but for simple use cases to show how to use your code, it's great. Check out the specifics below.

http://docs.python.org/2.7/library/doctest.html#doctest