Failed example:
p.parse_name('Adams, Michael')
# doctest: +NORMALIZE_WHITESPACE
Expected:
{'first_name': 'Michael', 'last_name': 'Adams','initials': 'MA'}
Got:
{'first_name': 'Michael', 'last_name': 'Adams', 'initials': 'MA'}
The docstring is -
>>> p.parse_name('Adams, Michael')
... # doctest: +NORMALIZE_WHITESPACE
{'first_name': 'Michael', 'last_name': 'Adams','initials': 'MA'}
The Doctest Module finds patterns in the docstring that looks like interactive shell commands. The input and expected output are included in the docstring, then the doctest module uses this docstring for testing the processed output.
When the tests include values that are likely to change in unpredictable ways, and where the actual value is not important to the test results, you can use the ELLIPSIS option to tell doctest to ignore portions of the verification value.
From the docs:
When specified, all sequences of whitespace (blanks and newlines) are treated as equal. Any sequence of whitespace within the expected output will match any sequence of whitespace within the actual output
','
contains no sequence of whitespace, so is not treated as equal to ', '
.
You might want to read the warnings section of the docs:
Python doesn’t guarantee that the key-value pairs will be printed in any particular order, so a test like
>>> foo() {"Hermione": "hippogryph", "Harry": "broomstick"}
is vulnerable! One workaround is to do
>>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"} True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With