Issue #256 new

path issue with -m doctest

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 foo.py 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 (5)

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

  2. James Tauber reporter

    Possibly relevant: if I create a bar.py that prints sys.path then python bar.py 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.

  3. 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)

  4. Log in to comment