jeudi 28 septembre 2017

Sphinx Doctest Fails Due to NameError

I have the following simple example that fails when I run make doctest.

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

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

The output is shown below.

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.

It looks like somehow Sphinx isn't recognizing that my_func() is a function in the module foo. I'm not sure how to resolve this. What has me particularly confused is that if I run python -m doctest -v foo.py, it passes.

Can anyone offer any insight here?

Aucun commentaire:

Enregistrer un commentaire