如何让 Sphinx 测试文档中嵌入的代码?
如果此代码是我的文档中的块引用,那么我需要做什么才能使 Sphinx 在文档生成了吗?我尝试将
.. testcode::
import datetime
def today():
return datetime.datetime.now().date()
if True:
today()
.rst
源代码和 Sphinx doctest 扩展添加到 conf.py
中,但收到错误消息,抱怨函数第一行出现意外缩进身体。 Sphinx的doctest能够运行文档中定义的函数吗?
If this code is a blockquote in my documentation, what do I need to do to make Sphinx run it when the documentation is generated? I tried adding
.. testcode::
import datetime
def today():
return datetime.datetime.now().date()
if True:
today()
to one of the .rst
sources and the Sphinx doctest extension to conf.py
, but I got an error complaining about unexpected indentation on the first line of the function body. Is Sphinx's doctest able to run functions defined in the documentation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
testcode
指令需要匹配的testoutput
指令。这是文档中的示例。
The
testcode
directive needs a matchingtestoutput
directive.Here's the example from the documentation.