No Python code coverage on Pull request even though report is being processed

Hi,
I am not able to get any coverage report in the Pull request but main Branch reports the coverage just fine. I am always getting No Coverage information in PR analysis.

Log:

INFO: Sensor Python Sensor [python]
INFO: Starting global symbols computation
INFO: 85 source files to be analyzed
INFO: 85/85 source files have been analyzed
INFO: Starting rules execution
INFO: 85 source files to be analyzed
INFO: 85/85 source files have been analyzed
INFO: Starting test sources highlighting
INFO: 18 source files to be analyzed
INFO: 18/18 source files have been analyzed
INFO: Sensor Python Sensor [python] (done) | time=6065ms
INFO: Sensor Cobertura Sensor for Python coverage [python]
INFO: Python test coverage
INFO: Parsing report '/home/user/workspace/xxxx_PR-151/coverage.xml'
ERROR: Cannot resolve the file path xxxx/templates/403.html' of the coverage report, the file does not exist in all 'source'.
ERROR: Cannot resolve 53 file paths, ignoring coverage measures for those files
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=175ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Processing report '/home/user/workspace/xxxx_PR-151/pytest_xunit.xml'
  • ALM used : GitHub
  • CI system used : Jenkins
  • Scanner command used :
sh "${SCANNER_HOME}/bin/sonar-scanner -Dsonar.login=${SONAR_LOGIN} \
                        -Dsonar.python.coverage.reportPaths=coverage.xml \
                        -Dsonar.python.xunit.reportPath=pytest_xunit.xml \
                        -Dsonar.python.version=3.9 \
                        -Dsonar.sources=./XXXXX \
                        -Dsonar.projectBaseDir=. \
                        -Dsonar.projectKey=${PROJECT_NAME} \
                        -Dsonar.organization=${SONAR_ORGANIZATION} \
                        -Dsonar.pullrequest.key=${CHANGE_ID} \
                        -Dsonar.pullrequest.branch=${CHANGE_BRANCH} \
                        -Dsonar.pullrequest.base=${CHANGE_TARGET} \
                        -Dsonar.pullrequest.key=${CHANGE_ID}"

sonar-project.properties

sonar.organization=xxx
sonar.projectKey=xxxx
sonar.projectName=xxxx
sonar.projectVersion=1.0
sonar.sources=xxx
sonar.tests=xxx
sonar.test.inclusions=xxxx/tests/test_*.py
sonar.exclusions=xxxx/tests/test_*.py
sonar.host.url=https://sonarcloud.io
sonar.language=py
sonar.python.version=3.9
sonar.python.coverage.reportPaths=coverage.xml
sonar.python.xunit.reportPath=pytest_xunit.xml

Other details

  • Languages of the repository : Python
  • Error observed
    No Coverage information
    No Duplication information

Hi,

It looks like the paths in your report don’t match the paths analysis is seeing in the directory.

I guess you’ve redacted a sensitive project name out of these paths, but I still clearly see the difference between where the coverage report is: in a directory named xxxx_PR-151 and where the coverage report says the files are: in a directory named simply xxxx.

 
HTH,
Ann

Thanks for your reply, I am still unsure what needs to be changed here.
what I understand directory named xxxx_PR-151 is auto generated on the PR branch, and the source directory is xxxx. So I am not sure why scanner is looking at the xxxx directory not xxxx_PR-151 directory for the PR analysis.

please check the sonar-project.properties and let me know where should I change.

Hi,

Because the xxxx directory is what’s referenced in the coverage reports. You should crack the report open and take a look inside.

 
HTH,
Ann

No, it’s already in the right directory and trying to reference sub directories,

INFO: Base dir: /home/ssm-user/workspace/xxxx_PR-151/
INFO: Parsing report ‘/home/ssm-user/workspace/xxxx_PR-151/coverage.xml’
ERROR: Cannot resolve the file path ‘yyyyy/templates/403.html’ of the coverage report, the file does not exist in all ‘source’.

yyyy here is the source directory inside the Base dir and it’s available in the path
/home/ssm-user/workspace/xxxx_PR-151/yyyyy/templates/403.htm

but some how sonar is not able to resolve the relative path

Hi,

The error is telling you that analysis doesn’t see the files listed in the coverage report. Typically that’s a path mis-match. So that’s where you need to look.

 
HTH,
Ann