doctest预期为True,得到True

Hel*_*lad 1 python doctest

doctest很难控制。我遇到了这样的问题

功能

from collections import namedtuple

Match = namedtuple('Match', ['token_string', 'normalised_token',
                     'brand_name', 'brand_id',
                     'score'])


def make_match(tokens, normalised, brand, score):
"""
Examples:
>>> make_match('Jack Jones','JackJones',('Jack Jones','X023'),0.6)==Match('Jack Jones','JackJones','Jack Jones','X023',0.6)
True 
>>> make_match('Jack Jones','JackJones',('Jack Jones','X023'),0.6)==('Jack Jones','JackJones','Jack Jones','X023',0.6)
True
>>> match=make_match('Jack Jones','JackJones',('Jack Jones','X023'),0.6)
>>> match.token_string=='Jack Jones'
True
"""
return Match(token_string=tokens,
         normalised_token=normalised,
         brand_name=brand[0],
         brand_id=brand[1],
         score=score)
Run Code Online (Sandbox Code Playgroud)

但是有一个错误

Failed example:
make_match('Jack Jones','JackJones',('Jack Jones','X023'),0.6)==Match('Jack Jones','JackJones','Jack Jones','X023',0.6)
Expected:
    True 
Got:
    True
Run Code Online (Sandbox Code Playgroud)

1个项目有故障:

难道不是完全匹配了吗?非常感谢利用率4中的1。make_match 测试失败 1个失败。

che*_*ner 5

您在指定期望返回值的行上有尾随空格,因此doctest实际上是将字符串"True "与的实际返回值进行比较True