Documenting the basics
Python provides out-of-the-box capability to put comments in code known as docstrings. Docstrings can be read when looking at the source and also when inspecting the code interactively from a Python shell. In this recipe, we will demonstrate how these interactive docstrings can be used as runnable tests.
What does this provide? It offers easy-to-read code samples for the users. Not only are the code samples readable, they are also runnable, meaning we can ensure the documentation stays up to date.
How to do it...
With the following steps, we will create an application combined with runnable docstring comments, and see how to execute these tests:
- Create a new file named
recipe16.pyto contain all the code we write for this recipe. ...