【发布时间】:2013-06-10 03:25:04
【问题描述】:
在 Python (3.3.2) doctest 中,省略号 (...) 可以匹配任何字符串。所以,对于下面的代码
def foo():
"""
>>> foo()
hello ...
"""
print("hello world")
在运行 doctest 时,它不应该引发任何错误。但是
$ python -m doctest foo.py
**********************************************************************
File "./foo.py", line 3, in foo.foo
Failed example:
foo()
Expected:
hello ...
Got:
hello world
**********************************************************************
1 items had failures:
1 of 1 in foo.foo
***Test Failed*** 1 failures.
我必须做什么才能启用省略号?据我所知,它默认是禁用的。
我知道添加# doctest: +ELLIPSIS,如下面的代码,解决它,但我喜欢为所有测试启用省略号。
def foo():
"""
>>> foo() # doctest: +ELLIPSIS
hello ...
"""
print("hello world")
【问题讨论】:
标签: python python-3.x ellipsis doctest