Why pytho coverage is not picked up in sonarqube?

Hi I have setup sonarqube in Azure DevOps Pipeilnes in the following way:

          - task: SonarQubePrepare@5
            condition: succeededOrFailed()
            displayName: 'Prepare analysis on SonarQube'
            inputs:
              SonarQube: 'xxx-connection'
              scannerMode: 'CLI'
              cliProjectKey: 'xxxx'
              configMode: 'manual'
              continueOnError: 'true'
              Dsonar.projectKey: 'xxx'
              cliProjectName: 'xxxx'
              Dsonar.sources: ./
              Dsonar.host.url: xxxx
              Dsonar.login: xxxx
              extraProperties: |
                sonar.core.codeCoveragePlugin=cobertura
                sonar.python.coverage.reportPaths=$(System.DefaultWorkingDirectory)/coverage-reports/coverage-report.xml
                sonar.exclusions=**/*.pyc
                sonar.projectKey=xxxxx
                sonar.projectName=xxxxx
                sonar.sources=./
                sonar.host.url=xxxxx
                sonar.login=xxxx

And in the pipeline I can see that code coverage is being picked up correctly:

INFO: Sensor Python Sensor [python] (done) | time=67071ms

INFO: Sensor Cobertura Sensor for Python coverage [python]

INFO: Python test coverage

INFO: Parsing report 'xxxxx/_work/57/s/coverage-reports/coverage-report.xml'

INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=1553ms

However in sonarqube I am still seeing 0% code coverage (while in the report is 80%…)
Why is that? What else I need to check if its working?

Hey there.

As requested in the template post – what version of SonarQube are you using?

Hi
We are using Enterprise Edition Version 9.9 build 65466

Thanks!

First things first, your pipeline configuration is a bit messy. This probably has no impact on importing coverage measures, but it’s still… a lot. You should be able to simplify it down to:

   - task: SonarQubePrepare@5
            condition: succeededOrFailed()
            displayName: 'Prepare analysis on SonarQube'
            inputs:
              SonarQube: 'xxx-connection'
              scannerMode: 'CLI'
              configMode: 'manual'
              cliProjectKey: 'xxxx'
              cliProjectName: 'xxxx'
              cliSources: '.'
              continueOnError: 'true'
              extraProperties: |
                sonar.python.coverage.reportPaths=$(System.DefaultWorkingDirectory)/coverage-reports/coverage-report.xml

As long as the xxx-connection SonarQube service connection has a valid URL/credentials, there’s no need to repeat the information several times.

Second, I would suggest turning on DEBUG level logging – adding sonar.verbose=true to your extraProperties blog. This should show whether or not the scanner is saving coverage measures for files in the coverage report.

And finally, could you share a screenshot of SonarQube where you see 0% coverage being reported?