gpt4 book ai didi

python - 如何让 Sphinx 测试文档中嵌入的代码?

转载 作者:行者123 更新时间:2023-11-28 16:54:42 24 4
gpt4 key购买 nike

如果这段代码是我文档中的 block 引用,我需要做什么才能制作 Sphinx在生成文档时运行它?我尝试添加

.. testcode::

import datetime
def today():
return datetime.datetime.now().date()
if True:
today()

.rst 来源之一和 conf.py 的 Sphinx doctest 扩展,但我收到一个错误,提示函数第一行出现意外缩进 body 。 Sphinx 的 doctest 是否能够运行文档中定义的函数?

最佳答案

testcode 指令需要匹配的 testoutput 指令。

这是文档中的示例。

.. testcode::

print 'Output text.'

.. testoutput::
:hide:
:options: -ELLIPSIS, +NORMALIZE_WHITESPACE

Output text.

关于python - 如何让 Sphinx 测试文档中嵌入的代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2021671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com