coveragepy
coveragepy copied to clipboard
sys.path is wrong when using coverage as a module and python version >= 3.7
Describe the bug
When the tested program is run from the coverage module (-m coverage run), the sys.path is wrong.
To Reproduce
Create the following small python script:
#!/usr/bin/env python3
import sys
print(sys.path)
- Assuming that the script is in "foo/foo-bin.py" file.
- use coverage version >= 5.0
- python version >= 3.7
The first entry in sys.path is the absolute path of the current working directory from where you typed the command.
Alternatively repro.zip contains a tox test case (using python 3.5 to 3.8) .
Expected behavior
The first entry should be the absolute path of the directory where the script is
Additional context
Works as expected with python version < 3.7 or coverage < 5.0
Thanks. Considering how much code I have to test that these things are the same, I'm chagrined to see that you are right. When running a file not in the current directory, "python" and "python -m coverage run" set sys.path[0] differently.
After investigating a little further, I saw that coverage versions 5.0.0, 5.0.1, 5.0.2 also fails with python 3.5, 3.6, 3.7 and 3.8.
@d-fence Can you help me understand how the sys.path change affects your program? It looks harder and harder to guarantee that the path will be identical both with and without coverage.
I'm trying to decide if this is worth pursuing. Do you have any more information?
Anecdotally, having the wrong sys.path entry leads to one program having a module not found exception. This would be very good to have fixed for me at least.
If someone can provide more information, feel free to re-open this.