doctest expect True,得到了真实

时间:2014-07-28 14:20:23

标签: 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)

但收到错误

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项失败:

预期不符合匹配吗? 非常感谢你    util.make_match中的1/4 测试失败 1次失败。

1 个答案:

答案 0 :(得分:5)

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