The sonar don't register the code coverage values in python project

Hi, i am needing a help

My sonar don’t register the code coverage values, show only 0%, below is my the azure pipeline

jobs:
- job: 
  displayName: Sonar
  pool:
    name: default
 
  steps:
    - task: SonarQubePrepare@5
      inputs:
        SonarQube: SonarQube
        scannerMode: CLI
        configMode: manual
        cliProjectKey: ${{parameters.ProjectName}}
        extraProperties: |    
              sonar.verbose=true
              sonar.python.version=3.8
              sonar.sources=.
              sonar.tests=.
              sonar.test.inclusions=**/*.tests.*
              sonar.language=py
              sonar.python.coverage.reportPaths=$(System.DefaultWorkingDirectory)/**/cobertura-coverage.xml
              sonar.python.xunit.reportPath=$(System.DefaultWorkingDirectory)/$(EnginePath)/test.xml
              sonar.exclusions=**/*.sql,**/*.pks,**/*.pkb,**/*__init__.py,**/*main.py
              sonar.sourceEncoding=UTF-8

   - script: coverage run -m pytest
      displayName: 'Run unit tests'

    - script: coverage xml
      displayName: 'Run code coverage'

    - task: PublishCodeCoverageResults@1
      displayName: 'Publish CodeCoverage Results'
      inputs:
        codeCoverageTool: coverage
        summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml

    # Run Code Analysis task
    - task: SonarQubeAnalyze@5

    # Publish Quality Gate Result task
    - task: SonarQubePublish@5
      inputs:
        pollingTimeoutSec: '300'   
INFO
17:19:06.552 INFO: Sensor Python Sensor [python] (done) | time=30529ms

17:19:06.552 INFO: Sensor Cobertura Sensor for Python coverage [python]

17:19:06.552 DEBUG: Using pattern 'D:\TFS\Agents\TPRB1048-v3_1\_work\71\s/**/cobertura-coverage.xml' to find reports

17:19:06.669 WARN: No report was found for sonar.python.coverage.reportPaths using pattern D:\TFS\Agents\TPRB1048-v3_1\_work\71\s/**/cobertura-coverage.xml

17:19:06.669 INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=117ms

17:19:06.670 INFO: Sensor PythonXUnitSensor [python]

17:19:06.670 DEBUG: Using pattern 'D:\TFS\Agents\TPRB1048-v3_1\_work\71\s/$(EnginePath)/test.xml' to find reports

17:19:06.785 WARN: No report was found for sonar.python.xunit.reportPath using pattern D:\TFS\Agents\TPRB1048-v3_1\_work\71\s/$(EnginePath)/test.xml

17:19:06.786 INFO: Sensor PythonXUnitSensor [python] (done) | time=115ms

17:19:06.786 INFO: Sensor JaCoCo XML Report Importer [jacoco]

17:19:06.787 INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations: target/site/jacoco/jacoco.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml

17:19:06.789 INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer

17:19:06.789 INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms

17:19:06.789 INFO: Sensor JavaScript inside YAML analysis [javascript]

17:19:06.800 INFO: No input files found for analysis

17:19:06.801 INFO: Hit the cache for 0 out of 0

17:19:06.802 INFO: Miss the cache for 0 out of 0

SonarQubeEnterprise LTS 9.9
Python version is 3.8.8

Hi,

Welcome to the community!

Can you share the exact path to at least one of your coverage reports?

 
Thx,
Ann

Hi Ann,
Confirm please if i understant your question

/usr/bin/dotnet /tfs/Agents/AgentV1/_work/_tasks/PublishCodeCoverageResults_2a7ebc54-c13e-490e-81a5-d7561ab7cd97/1.180.0/netcoreapp2.0/ReportGenerator.dll -reports:/tfs/Agents/AgentV1/_work/1490/s/**/coverage.xml -targetdir:/tfs/Agents/AgentV1/_work/_temp/cchtml -reporttypes:HtmlInline_AzurePipelines
2024-01-26T20:03:00: Arguments
2024-01-26T20:03:00:  -reports:/tfs/Agents/AgentV1/_work/1490/s/**/coverage.xml
2024-01-26T20:03:00:  -targetdir:/tfs/Agents/AgentV1/_work/_temp/cchtml
2024-01-26T20:03:00:  -reporttypes:HtmlInline_AzurePipelines
2024-01-26T20:03:01: Writing report file '/tfs/Agents/AgentV1/_work/_temp/cchtml/index.html'
2024-01-26T20:03:01: Report generation took 0.2 seconds
Generated code coverage html report: /tfs/Agents/AgentV1/_work/_temp/cchtml
Reading code coverage summary from '/tfs/Agents/AgentV1/_work/1490/s/coverage.xml'
Async Command Start: Publish code coverage
Publishing coverage summary data to TFS server.
 Lines- 293 of 293 covered.
 Branches- 0 of 0 covered.
Modifying Cobertura Index file
Publishing code coverage files to TFS server.
Uploading 9 files
File upload succeed.
Published '/tfs/Agents/AgentV1/_work/_temp/cchtml' as artifact 'Code Coverage Report_574783'

Hi Ann,
I found the problem, was wrong the reportPaths

Before
sonar.python.coverage.reportPaths=$(System.DefaultWorkingDirectory)/**/cobertura-coverage.xml

After
sonar.python.coverage.reportPaths=coverage.xml

1 Like

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