Search code examples
pythonunit-testingpytestcode-coveragecoverage.py

Coverage "No source for code" with pytest


I am trying to measure code coverage by my pytest tests. I tried following the quick start guide of coverage (https://coverage.readthedocs.io/en/6.4.1/)

When I run my test with the following command, everything seems fine

coverage run -m pytest tests/
===================================== test session starts ======================================
platform linux -- Python 3.10.4, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/arnaud/Documents/Github/gotcha
collected 4 items                                                                              

tests/preprocessing/test_preprocessing.py ....                                           [100%]

====================================== 4 passed in 0.30s =======================================

However, when I try to access the report with either of those commands,

coverage report

coverage html

I get the following message:

No source for code: '<project_directory>/config-3.py'.

I did not find an appropriate solution to this problem so far


Solution

  • It is possible to ignore errors using the command

    coverage html -i
    

    which solved my issue