Revisiting the doctest caveats
In the previous chapter, we developed a list of things to watch out for when writing doctests. When discussing these, unit tests were sometimes mentioned as an alternative that did not suffer from the same problems. But are unit tests really immune to these problems, or do they just make the problems easier to avoid or address? In this section, we revisit the doctest caveats and consider how susceptible unit tests are to the same or similar issues.
Environmental dependence
The first doctest caveat discussed was environmental dependence: relying on the implementation details of code other than the code actually being tested. Though this type of dependence can happen with unit tests, it is less likely to occur. This is because a very common way for this type of dependence to creep into doctests is due to reliance on the printed representation of objects, as they are displayed in a Python shell session. Unit tests are far removed from the Python shell. It requires...