在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")