更新时间:2023-08-21 20:24:16
即使已经在评论中解决了,这里的答案也可以帮助访问问题的人,更容易找到解决方案.
Even if it was already solved in the comment, here the answer to help people visiting the question, finding the solution easier.
问题是文档测试块的缩进:
The problem was the indent of the block of the doctest:
def my_func():
'''
Dummy test function. Returns the number 5.
.. doctest::
>>> my_func()
5
'''
return 5
只有在 doctest 块之后缩进的行才被视为测试的一部分并进行测试.
only the lines that are indented after the doctest block are considered part of the test and are tested.