Coding a test harness for doctest
The tests we have written so far are very simple, because the function we are testing is simple. There are two inputs and one output with no side effects. No objects have to be created. This isn't the most common use case for us. Often, we have objects that interact with other objects.
doctest module supports creating objects, invoking methods, and checking results. With this recipe, we will explore this in more detail.
An important aspect of
doctest is that it finds individual instances of
docstrings, and runs them in a local context. Variables declared in one
docstring cannot be used in another
How to do it...
- Create a new file called
recipe19.pyto contain the code from this recipe.
- Write a simple ...