문제

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