【问题标题】:doctest expected True, got Truedoctest 预期为真,得到真
【发布时间】:2014-07-28 14:20:23
【问题描述】:

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

不是 Expected 完全匹配 Got 吗? 非常感谢你 4 个中的 1 个利用率.make_match 测试失败 1 次失败。

【问题讨论】:

    标签: python doctest


    【解决方案1】:

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

    【讨论】:

    • 或者文件 EOL 是 Windows (\r\n) 并且您正在 Linux 下测试 (\n)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    • 1970-01-01
    相关资源
    最近更新 更多