0

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

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

       from foo import my_func

    .. 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?

edit: I previously posted a similar, related question about Sphinx not recognizing my tests. I think this is a distinct question, because now Sphinx is recognizing the test but failing for some reason that escapes me, so I created a separate post rather than extend the previous topic in a new direction.

edit 2: Some helpful links down below. I added a testsetup declaration, but I still have the same issue.

hobscrk777
  • 2,347
  • 4
  • 23
  • 29

0 Answers0