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'}
有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top