由于NameError,Sphinx Doctest失败

时间:2017-09-28 19:52:58

标签: python testing automated-tests python-sphinx

我有以下简单示例,当我运行make doctest时失败。

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

       from foo import my_func

    .. doctest::

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

输出如下所示。

Document: foo
-------------
**********************************************************************
File "foo.rst", line 7, in default
Failed example:
    my_func()
Exception raised:
    Traceback (most recent call last):
      File "C:\Apps\Anaconda2\lib\doctest.py", line 1315, in __run
        compileflags, 1) in test.globs
      File "<doctest default[0]>", line 1, in <module>
        my_func()
    NameError: name 'my_func' is not defined
**********************************************************************
1 items had failures:
   1 of   1 in default
1 tests in 1 items.
0 passed and 1 failed.
***Test Failed*** 1 failures.

Doctest summary
===============
    1 test
    1 failure in tests
    0 failures in setup code
    0 failures in cleanup code
build finished with problems, 10 warnings.
Testing of doctests in the sources finished, look at the results in _build\doctest\output.txt.

看起来Sphinx似乎并未认识到my_func()是模块foo中的一个函数。我不知道如何解决这个问题。让我特别困惑的是,如果我运行python -m doctest -v foo.py,它会通过。

这里有人可以提供任何见解吗?

编辑:我之前发布了一个类似的相关问题,关于Sphinx没有认出我的测试。我认为这是一个截然不同的问题,因为现在Sphinx正在认识到测试,但由于某些原因导致我失败,所以我创建了一个单独的帖子而不是将上一个主题扩展到新的方向。

编辑2:下面有一些有用的链接。我添加了testsetup声明,但我仍然遇到同样的问题。

0 个答案:

没有答案