在 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.
我必须做什么才能启用省略号?据我所知,默认情况下它是禁用的。
我知道 add # doctest: +ELLIPSIS
,如下面的代码所示,可以解决它,但我喜欢为所有测试启用省略号。
def foo():
"""
>>> foo() # doctest: +ELLIPSIS
hello ...
"""
print("hello world")