Python Coverage Analysis warning

Must-share information (formatted with Markdown):

  • SonarQube Developer Edition Version 9.4 (build 54424)
  • Trying to get accurate coverage in python

I am getting this warning… Do you know how to fix it?

The following error(s) occurred while trying to import coverage report:
Cannot resolve the file path '__init__.py' of the coverage report, ambiguity, the file exists in several 'source'.%nCannot resolve 5 file paths, ignoring coverage measures for those files

Thanks!

hey @adric1 ,

Welcome to our community!
It looks like the coverage report contains 5 file having just __init__.py as file path, so the analyzer is not able to tell what files it’s referring to.

Could you please share with us how you generate coverage report?

Hey! Thanks for the response:

We have this .coveragerc config file:

[run]
branch = True
source = 
    utils
    tests

[report]
skip_covered = True

[xml]
output = coverage-reports/coverage-report.xml

And we launch the pytest with the following command:
pytest --cov -n 4 --cov-report xml --junitxml=xunit-reports/junit-report.xml

Seems to work properly, but for some reason we get that warning.

Thanks!

@ Andrea_Guarino

BUMP Adrea

hi @adric1 ,
Sorry for late reply. Is it expected to have also tests as source in .coveragerc? If I’m not mistaken this means test files are also taken into account in coverage computation.

source = 
    utils
    tests

Could you please share coverage-reports/coverage-report.xml?

Hey.

Seems that using source in .coveragerc generates a bad formated coverage-report.xml.
Switching to include fixes it and generates the correct xml.

include = 
    utils/*
    tests/*

Hope it helps.

Adrián

1 Like