我正在使用Sphinx autodoc来记录我的Python代码。我的文档中的示例包含:
例如:
Then you process file `example.txt` with `frobnicate()`:
>>> with open('example.txt', 'w') as f:
... _ = f.write("first boring line\\n")
... _ = f.write("second boring line\\n")
>>> frobnicate('example.txt')
True
我希望Sphinx autodoc隐藏不感兴趣的设置代码,以便Sphinx呈现的HTML输出仅包含:
Then you process file example.txt with frobnicate():
>>> frobnicate('example.txt')
True
显然我仍然希望doctest像往常一样执行整个例子。
答案 0 :(得分:2)
您可以将不感兴趣的设置代码放在testsetup
块中。
.. testsetup:: *
with open('example.txt', 'w') as f:
_ = f.write("first boring line\\n")
_ = f.write("second boring line\\n")
Then you process file `example.txt` with `frobnicate()`:
>>> frobnicate('example.txt')
True