Sphinx Doctest Not Finding Tests

2019-07-31 16:31发布

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

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.

1条回答
Lonely孤独者°
2楼-- · 2019-07-31 16:54

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

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

查看更多
登录 后发表回答