【问题标题】:Print out method / function name where the Sphinx directive is coming from打印出 Sphinx 指令来自的方法/函数名称
【发布时间】:2019-04-10 06:21:41
【问题描述】:

我根据 ToDo 示例在 pytest 中为 Sphinx 文档创建了自己的扩展。 这是从每个 pytest test_function 的每个文档字符串中读取和收集“test_summary”。

def test_sphinx():
    """
    This is the first sentence in the test_sphinx test case.

    .. test_summary:: This is the test summary one

    """
    pass 

这工作正常。

现在我喜欢将这些 test_summaries 收集到一个自己的文件中。 现在的例子:

File collection_of_test_summaries:


Test_summary
This is the test summary one

这也有效。 但我喜欢打印出函数名,在这里:每个指令的“test_sphinx”,就像这样:

File collection_of_test_summaries:

test_sphinx:
Test_summary
This is the test summary one

根据 Sphinx ToDo 示例,我有文档(模块)名称,但找不到函数名称。

Sphinx ToDo 示例: https://www.sphinx-doc.org/en/master/development/tutorials/todo.html

【问题讨论】:

    标签: python pytest python-sphinx


    【解决方案1】:

    我找到了解决办法:

    我用

    self.content.items[0][0].split()[-1]
    

    里面

    run()
    

    功能

    class MyDirective(SphinxDirective):
    

    类。

    这很好用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-02
      • 1970-01-01
      • 2019-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多