Sphinx Doctest 没有找到测试 [英] Sphinx Doctest Not Finding Tests

查看:41
本文介绍了Sphinx Doctest 没有找到测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何让 doctest 与 Sphinx 一起工作,但它似乎没有找到我的测试.我有以下简单的例子.

I'm trying to figure out how to get doctest working with Sphinx, but it doesn't seem to be finding my tests. I have the following simple example.

def my_func():
    '''
    Dummy test function. Returns the number 5.
    .. doctest::

    >>> my_func()
    5
    '''
    return 5

当我运行 make doctest 时,输出告诉我有零个测试.我很确定我已经正确配置了一些东西,因为如果我运行 make html 然后转到我的 index.html 文件,我会看到函数 my_func() 包含在文档.

When I run make doctest, the output tells me that there were zero tests. I'm pretty sure I have things configured correctly because if I run make html and then go to my index.html file, I see the function my_func() included in the documentation.

我在这里忽略了一些简单的东西吗?感谢您的帮助.

Am I overlooking something simple here? Thanks for your help.

推荐答案

即使已经在评论中解决了,这里的答案也可以帮助访问问题的人,更容易找到解决方案.

Even if it was already solved in the comment, here the answer to help people visiting the question, finding the solution easier.

问题是文档测试块的缩进:

The problem was the indent of the block of the doctest:

def my_func():
    '''
    Dummy test function. Returns the number 5.
    .. doctest::

        >>> my_func()
        5
    '''
    return 5

只有在 doctest 块之后缩进的行才被视为测试的一部分并进行测试.

only the lines that are indented after the doctest block are considered part of the test and are tested.

这篇关于Sphinx Doctest 没有找到测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆