15.3 Handling common doctest issues
A docstring that contains an example is part of good Python programming. The way the doctest tool uses literal matching of the expected text output against the actual text can make testing complicated for Python objects that do not have a consistent text representation.
For example, object hash values are randomized. This often results in the order of elements in a set collection being unpredictable. We have several choices for creating test case example output:
Write examples that can tolerate randomization. One technique is by sorting the elements of a set into a defined order.
Stipulate a specific value for the PYTHONHASHSEED environment variable.
There are several other considerations beyond simple variability in the location of keys or items in a set. Here are some other concerns:
The id() and repr() functions may expose an internal object ID. No guarantees can be made...