path issue with -m doctest

Issue #256 closed
James Tauber created an issue

I have a doctest in a separate .rst that I am able to run with

python -m doctest -v foo.rst

(where foo.rst includes an import foo in it and is alongside foo.rst in the directory).

However, when I attempt

coverage run -m doctest -v foo.rst

the tests all fail (and no coverage data is collected) because doctest is unable to import foo.

Comments (6)

  1. James Tauber reporter

    I'm investigating this myself but wanted to log the bug in case someone beat me to it.

  2. James Tauber reporter

    If foo.rst has something like

    >>> import sys
    >>> sys.path

    we can see that the issue is (as one might have guessed) that when run with python, sys.path has '' whereas when run with coverage run, sys.path does not.

  3. James Tauber reporter

    Possibly relevant: if I create a that prints sys.path then python does not include '' in the path but python -m bar does.

    So it is as if coverage run -m is not following the python -m behaviour of adding the current directory to the path.

  4. James Tauber reporter

    My current workaround is to create a file:

    import doctest
    import sys
    doctest.testfile(sys.argv[1], verbose=True)

    and have coverage run that file (with the testfile passed in)

  5. Log in to comment