SonarCLoud Code Coverage in Github action for Python not working

I am trying to implement code coverage in the sonar cloud using GitHub actions.
It shows it is integrated, But coverage is 0.0%
From the Analysis details, I found two warnings.

Could not find ref ‘main’ in refs/heads, refs/remotes/upstream or refs/remotes/origin. You may see unexpected issues and changes. Please make sure to fetch this ref before pull request analysis.


The following error(s) occurred while trying to import coverage report:
Cannot resolve 63 file paths, ignoring coverage measures for those files%nCannot
resolve the file path ‘src/adapters/’ of the coverage report, ambiguity,
the file exists in several ‘source’.

The GitHub action is

  - name: Run tests
    run: poetry run pytest tests/unit tests/integration --cov-report=xml --cov-branch  --cov=adapters --cov=domain --cov=entrypoints --cov=ports --cov=schemas --cov=service_layer --cov=utils

Sonar properties are
Apologies, If I miss any important details


Welcome to the community!

The first warning you posted isn’t related, but it will likely have impact on the detection of new code, so you’ll want to pursue it separately.

The second warning is what’s pertinent here:

I’ll be honest and say I haven’t seen this particular variant before, but basically what it’s telling you is that your coverage report data was ignored because analysis couldn’t figure out which file each particular data point was for.

Am I correct in guessing from your coverage command that one report includes coverage for two types of test? If so, you might need to break that into separate files. The sonar.python.coverage.reportPaths parameter does accept a comma-delimited list of reports.


Hi, thanks for the feedback.
The issue basically is that --cov parameter takes both directories and modules as input. I had both directories and modules with same name. However, coverage lib does not have any problem generating this. But pytest-cov has.


Can you check your coverage report and see if it has multiple entries for the same file(s)?