9
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'}
Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169

1 Answers1

19

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
Eric
  • 95,302
  • 53
  • 242
  • 374
  • 2
    For the dict order issue, ``pprint`` is a nice solution also. ``from pprint import pprint as pp; pp(foo())``. ``pprint`` will sort keys and also help having a nice readable display of big structures. – vaab Dec 18 '14 at 05:51