【发布时间】:2019-10-01 17:28:21
【问题描述】:
考虑以下函数:
# in mymodule.py:
def myfunc(num,mystring):
"""
replicates a string
:param num: a positive integer
:param mystring: a string
:return: string concatenated with itself num times
:Example:
>>> num = 3
>>> mystring = "lol"
>>> myfunc(num, mystring)
"lollollol"
"""
return num*mystring
如何让 Sphinx doctest 工作,以验证
中的示例代码:Example:´ actually does work?
Whenever I runmake doctest`
它说运行了 3 次测试,但 1 次失败。删除最后两行,以
开头myfunc(num, mystring),
它说成功运行了 2 个测试。所以我一定在这条线上做错了。但是什么?
EDIT 这是完整代码的终端输出(回溯);似乎以某种方式找不到我为其编写文档字符串并且正在运行文档测试的函数:
Running Sphinx v1.8.3
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [doctest]: targets for 1 source files that are out of date
updating environment: [] 0 added, 1 changed, 0 removed
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
running tests...
Document: index
---------------
**********************************************************************
File "index.rst", line ?, in default
Failed example:
myfunc(num, mystring)
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python3.6/doctest.py", line 1330, in __run
compileflags, 1), test.globs)
File "<doctest default[2]>", line 1, in <module>
myfunc(num, mystring)
NameError: name 'myfunc' is not defined
**********************************************************************
1 items had failures:
1 of 3 in default
3 tests in 1 items.
2 passed and 1 failed.
***Test Failed*** 1 failures.
Doctest summary
===============
3 tests
1 failure in tests
0 failures in setup code
0 failures in cleanup code
build finished with problems.
Makefile:19: recipe for target 'doctest' failed
【问题讨论】:
-
@mzjn 我附上了回溯
标签: python python-sphinx doctest