Search code examples
pythoncode-coveragecoverage.py

coverage.py gives "No source for code", despite .coveragerc seemingly telling it where the code is


If I invoke python3 -m coverage run ... inside a docker container, I get a .coverage file as desired.

However, if I try to generate the html or text reports using that .coverage file outside of the container, I get:

No source for code: '/opt/anomaly/backplane/__init__.py'.
Aborting report output, consider using -i.

./backplane/__init__.py exists, and I have the following .coveragerc in the same directory:

[paths]
source =
    ./
    /opt/anomaly/.

It seems like coverage.py doesn't know that . and /opt/anomaly should be considered the same thing, despite the .coveragerc file intended to tell coverage.py that they are.

I've googled quite a bit, and found nothing.

I also generated the reports inside the container, and that worked fine. But I'd really rather generate them outside the container.


Update: Ned provided the useful information that only coverage combine uses [paths] in the .coveragerc.

Here's what I'm up against at this point:

+ ./bin/terminate-api
+ sleep 2
+ lses
+ ls -l .coverage .api-coverage
ls: cannot access '.coverage': No such file or directory
-rw-rw-r-- 1 root root 13358 Jul 22 14:15 .api-coverage
+ python3 -m coverage combine .api-coverage
+ lses
+ ls -l .coverage .api-coverage
ls: cannot access '.api-coverage': No such file or directory
-rw-r--r-- 1 dstromberg dstromberg 13358 Jul 22 14:15 .coverage
+ python3 -m coverage html
No source for code: '/opt/anomaly/backplane/__init__.py'.
Aborting report output, consider using -i.

BTW, I've now tried with a relative path in .coveragerc, and also with an absolute path in .coveragerc. Neither is working for me at the moment.

Note that .api-coverage and .coverage have the same length - I'm thinking .coverage should have a different length because of the changed paths. For the relative path, .coverage should be smaller, and with the absolute path, .coverage should be larger.

BTW, I'm using:

$ python3 -m coverage --version
below cmd output started 2019 Mon Jul 22 02:33:02 PM PDT
Coverage.py, version 4.5.3 with C extension
Documentation at https://coverage.readthedocs.io

Thanks!


Solution

  • Running executables .coverage requires runtime environment, which in your case can be provided inside the container instead of your host machine.

    This combined with deleting the trailing /. from my .coveragerc's /opt/anomaly/. path appears to have solved the problem.