doctest 预期 True,但得到 True
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)
但是出现了一个错误:
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
有 1 项测试失败了:
预期的结果和实际得到的结果不完全匹配,是不是?非常感谢。
在 utilization.make_match 中,有 1 个失败, 总共 4 个测试。
测试失败 1 个失败。1 个回答
6
你在写的那一行中,期望的返回值后面有多余的空格,所以 doctest
实际上是在把字符串 "True "
和真正返回的值 True
进行比较。