【问题标题】:Python doctest with a loop带有循环的 Python doctest
【发布时间】:2016-05-18 17:57:17
【问题描述】:

如果我需要在 doctest 中做一些事情怎么办:

'''
>>> for i in range(5):
        print i
'''

我明白了

    for i in range(5):
                     ^
SyntaxError: unexpected EOF while parsing

【问题讨论】:

  • 一行一行?
  • 使用...引出第二行及后续行,如the documentation所示。

标签: python unit-testing doctest


【解决方案1】:
>>> for i in range(5):
...     print i

您显示的内容有 print i 和省略号 (...) 在不同的行上。然后 doctest 无法知道您的代码是否超出了初始行;它会在后续行的开头查找省略号,以了解它是一个多行示例。

【讨论】:

    猜你喜欢
    • 2019-11-19
    • 1970-01-01
    • 2021-08-21
    • 2013-07-18
    • 2017-07-11
    • 2019-01-30
    • 1970-01-01
    • 2013-01-25
    • 2016-01-01
    相关资源
    最近更新 更多