Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dealing with the No source for code error in Python coverage

I have a new variant of this old "No source for code" issue.

"No source for code" message in Coverage.py

Here is the error I see:

$ coverage report
No source for code: '/home/pauljohn/GIT/projects/ml_grb/grb/packages/grb/tests/C:\Users\G33987\.conda\envs\grb\lib\site-packages\grb\review\review.py'.
Aborting report output, consider using -i.

I'm in Linux, working in a Git repository with a windows teammate "G33987". My current working directory is /home/pauljohn/GIT/projects/ml_grb/grb/packages/grb/tests, as you can see, and the virtual environment I'm using is in ~/venv-grb. Notice the super weird thing is that it is looking for a file in my tests folder with an appended full path to a teammate's installed "grb" package folder, "C:\Users\G33987.conda..."

I can add the "-i" flag to ignore problem, but I want to understand and fix.

In the other posts about this issue with coverage.py, the problem was linked to presence of old copy of .coverage in tests folder or to presence of *.pyc files. I've checked and our Git repository does not track any pyc files. However, by mistake it was tracking the original .coverage file. But we don't track that anymore and I've manually deleted it between runs.

So far, I have this workflow

  1. coverage erase
  2. find . -name "*.pyc" -exec rm {} \;
  3. coverage run --source=grb -m pytest .
  4. coverage report

I can run coverage report -i to ignore issue and the output does give line-by-line reports on the files in my own virtual environment. But I'm disgusted by ignoring an error. Where does reference to teammate's virtual environment come from? I'm not using a conda virtual environment, but rather I'm pure Python virtual environment.

Python 3.8.5
coverage 5.5
pytest 6.2.2
py 1.10.0
pluggy 0.13.1
like image 867
pauljohn32 Avatar asked Jul 03 '26 20:07

pauljohn32


1 Answers

The solution for me was to delete the .pytest_cache directory before running tests/coverage.

In my case, I believe I was using PyCharm in windows which was running the tests and writing to .pytest_cache with windows paths, then trying to run the project build tools via WSL.

I added the --cache-clear flag to pytest to stop this happening again.

like image 94
Ben Ellis Avatar answered Jul 06 '26 16:07

Ben Ellis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!