Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path issue with -m doctest #256

Open
nedbat opened this issue Aug 18, 2013 · 4 comments
Open

path issue with -m doctest #256

nedbat opened this issue Aug 18, 2013 · 4 comments
Labels
bug Something isn't working exotic Unusual execution environment

Comments

@nedbat
Copy link
Owner

nedbat commented Aug 18, 2013

Originally reported by James Tauber (Bitbucket: jtauber, GitHub: jtauber)


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.


@nedbat
Copy link
Owner Author

nedbat commented Aug 18, 2013

Original comment by James Tauber (Bitbucket: jtauber, GitHub: jtauber)


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

@nedbat
Copy link
Owner Author

nedbat commented Aug 18, 2013

Original comment by James Tauber (Bitbucket: jtauber, GitHub: jtauber)


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.

@nedbat
Copy link
Owner Author

nedbat commented Aug 18, 2013

Original comment by James Tauber (Bitbucket: jtauber, GitHub: jtauber)


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.

@nedbat
Copy link
Owner Author

nedbat commented Aug 18, 2013

Original comment by James Tauber (Bitbucket: jtauber, GitHub: jtauber)


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)

@nedbat nedbat added minor bug Something isn't working run labels Jun 23, 2018
@nedbat nedbat removed the 3.6 label Aug 17, 2018
@nedbat nedbat added exotic Unusual execution environment and removed minor run labels Jan 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working exotic Unusual execution environment
Projects
None yet
Development

No branches or pull requests

1 participant