Coverage Report percentage is not same in Azure DevOps and in SonarCloud

Hi Sonar Community,

I notice the Percentage Number of Code Coverage in Azure DevOps (Cobertura) is not same/equal Percentage Number in SonarCloud Coverage.

Azure DevOps: 90%

SonarCloud: 68.6%
image

May i know why is that ?

File: sonar-project.properties:

sonar.python.coverage.reportPaths=coverage-reports/coverage.xml

ADO-pipeline.yaml

 python -m pytest -v --cov=service --cov-report=xml:coverage-reports/coverage.xml --cov-branch --cov-fail-under=70 --cov-report=term-missing test

Please note: I didn’t scan yet the main branch in sonarcloud.

Kindly help.

Hey there.

Once you’ve scanned your main branch, you should be able to see the Code tab (including all files analyzed, which this “estimated after merge” figure represents) and understand what files are being included in this figure.

I think this will help you understand what could be the source of the discrepancy. For example – SonarCloud includes all files in the coverage calculation that have “executable lines” – not just the ones included in a coverage report. If you have a mixed-language project, that could be the source.

Hi Colin,

Noted, i thought the code coverage value is from the coverage.xml, but that is not the case.

How could i make SonarCloud to only calculate Coverage in folder /src & /service, and i still want sonar to scan all file & directory but exclude the coverage. - Is this possible ?

Thank you.

The Analysis Scope documentation should help you understand how you can exclude certain files from coverage (unfortunately, only exclusions are possible, not inclusions)

Thank you @Colin , that is helpful link :smiley:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.