带循环的 Python doctest

标签 python unit-testing doctest

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

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

我明白了

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

最佳答案

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

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

关于带循环的 Python doctest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37306981/

相关文章:

python - 在 doctest 中,有没有办法将 yaml 代码块视为变量?

python - 使用鼠标点击/事件获取像素位置

python - Pandas : Cumulative sum with moving window (following and preceding rows)

python - 如何按行值过滤和分组条目

delphi - 寻找具有良好单元测试覆盖率的开源Delphi项目

unit-testing - @WebAppConfiguration 未注入(inject)

unit-testing - grails 2.0.1 单元测试 NullPointerException 保存

python-3.x - 为什么 doctest 跳过对导入方法的测试?

python - 合并两个 Python 元组列表

python - 我可以在 python 中对内部函数进行单元测试吗?