Sonarqube python coverage.xml not transorated to service

Hello evryone. Im just strated imersion in this technology. can you please check and correct my script. at the moment my coverege.xml not translated to my service. its still 0.0%
sonar-scanner
-Dsonar.projectKey=backend-python
-Dsonar.sourses.inclusions=src
-Dsonar.test.inclusions=src/tests/test_*.py
-Dsonar.python.coverage.reportPaths=coverage.xml -Dsonar.host.url=https://
-Dsonar.login=sqp_

also I have sonar-project.properties file in repo
sonar.projectKey=backend-python
sonar.qualitygate.wait=true
sonar.python.coverage.reportPaths=coverage.xml
sonar.language=py
sonar.sourceEncoding=UTF-8
sonar.sources=src
sonar.tests=src/tests
sonar.sources.inclusions=src
sonar.test.inclusions=src/tests/

Hey there.

As noted in template post, can you tell us what version of SonarQube you’re using?

And what do the logs say?

INFO: SonarScanner 4.8.0.2856
I saw some error like ‘coverage.jacaco not defined’ so I fix it vie adding new line point to properties “sonar.coverage.jacoco.xmlReportPaths=src/tests/*.xml”
and my coverage still not uploaded in the project statistic

Summary

NFO: SonarScanner 4.8.0.2856
INFO: Java 11.0.17 Eclipse Adoptium (64-bit)
INFO: Linux 5.19.0-38-generic amd64
INFO: User cache: /home/yevhen/.sonar/cache
INFO: Analyzing on SonarQube server 9.9.0.65466
INFO: Default locale: “en_US”, source code encoding: “UTF-8”
INFO: Load global settings
INFO: Load global settings (done) | time=348ms
INFO: Server id: 243B8A4D-AYMW8jeVdiTaNaIVcVBG
INFO: User cache: /home/yevhen/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=148ms
INFO: Load/download plugins (done) | time=309ms
INFO: Process project properties
INFO: Process project properties (done) | time=2ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=5ms
INFO: Project key: polygon-backend-python
INFO: Base dir: /home/yevhen/python/polygon/polygon-backend-python
INFO: Working dir: /home/yevhen/python/polygon/polygon-backend-python/.scannerwork
INFO: Load project settings for component key: ‘polygon-backend-python’
INFO: Load project settings for component key: ‘polygon-backend-python’ (done) | time=68ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=102ms
INFO: Load active rules
INFO: Load active rules (done) | time=2856ms
INFO: Load analysis cache
INFO: Load analysis cache | time=141ms
INFO: Load project repositories
INFO: Load project repositories (done) | time=65ms
INFO: Indexing files…
INFO: Project configuration:
INFO: Excluded sources: src/tests/
INFO: Included tests: src/tests/
INFO: 111 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 117 files ignored because of scm ignore settings
INFO: Quality profile for py: Sonar way
INFO: ------------- Run sensors on module polygon-backend-python
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=67ms
INFO: Sensor Python Sensor [python]
WARN: Your code is analyzed as compatible with python 2 and 3 by default. This will prevent the detection of issues specific to python 2 or python 3. You can get a more precise analysis by setting a python version in your configuration via the parameter “sonar.python.version”
INFO: Starting global symbols computation
INFO: 101 source files to be analyzed
INFO: 101/101 source files have been analyzed
INFO: Starting rules execution
INFO: 101 source files to be analyzed
INFO: 101/101 source files have been analyzed
INFO: The Python analyzer was able to leverage cached data from previous analyses for 0 out of 101 files. These files were not parsed.
INFO: Sensor Python Sensor [python] (done) | time=6268ms
INFO: Sensor Cobertura Sensor for Python coverage [python]
INFO: Python test coverage
INFO: Parsing report ‘/home/yevhen/python/polygon/polygon-backend-python/src/tests/coverage.xml’
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=269ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=96ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=33ms
INFO: Sensor CSS Rules [javascript]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor CSS Rules [javascript] (done) | time=3ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=3ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=32ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=13ms
INFO: Sensor TextAndSecretsSensor [text]
INFO: 111 source files to be analyzed
INFO: 111/111 source files have been analyzed
INFO: Sensor TextAndSecretsSensor [text] (done) | time=467ms
INFO: Sensor VB.NET Project Type Information [vbnet]
INFO: Sensor VB.NET Project Type Information [vbnet] (done) | time=1ms
INFO: Sensor VB.NET Analysis Log [vbnet]
INFO: Sensor VB.NET Analysis Log [vbnet] (done) | time=25ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=1ms
INFO: Sensor IaC Docker Sensor [iac]
INFO: 1 source file to be analyzed
INFO: 1/1 source file has been analyzed
INFO: Sensor IaC Docker Sensor [iac] (done) | time=207ms
INFO: ------------- Run sensors on project
INFO: Sensor Analysis Warnings import [csharp]
INFO: Sensor Analysis Warnings import [csharp] (done) | time=2ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=88ms
INFO: SCM Publisher SCM provider for this project is: git
INFO: SCM Publisher 86 source files to be analyzed
INFO: SCM Publisher 86/86 source files have been analyzed (done) | time=970ms
INFO: CPD Executor 26 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 75 files
INFO: CPD Executor CPD calculation finished (done) | time=83ms
INFO: Analysis report generated in 176ms, dir size=588.8 kB
INFO: Analysis report compressed in 502ms, zip size=391.5 kB
INFO: Analysis report uploaded in 460ms
INFO: ANALYSIS SUCCESSFUL, you can find the results at:
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at
INFO: Analysis total time: 18.535 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 21.360s
INFO: Final Memory: 28M/100M
INFO: ------------------------------------------------------------------------

Hey there.

It sure looks like the coverage report is being read correctly.

INFO: Python test coverage
INFO: Parsing report ‘/home/yevhen/python/polygon/polygon-backend-python/src/tests/coverage.xml’
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=269ms

If you manually check the coverage.xml, is it reporting the coverage you expect (more than 0) on the files you expect? Feel free to share it here as well.

its seems what i expected

This looks like a test execution report rather than a coverage report. It shows the tests and how long they took to complete, but not coverage information.

How are you producing your code coverage report?

this is indeed my fault. I created it with my usual pytest-coverage command. can you help me with how it must be in Sonarcube?

I can point to the documentation on Python Test Coverage – but the help we can offer is limited. SonarQube just reads the report, it isn’t involved in producing them.

The coverage report shoud look like this

in everything my script looks well ?

'''
run in terminal
    $coverage run -m pytest                                        #run pytest under coverage data colecting
    $coverage xml                                                  #create coverage.xml by coverage library

    for collect covverage stat
run in terminal localy:
    sonar-scanner
   -Dsonar.projectKey=                     #keyname to my project
   -Dsonar.host.url=https://          #link to our host
   -Dsonar.login=                                                  #keyvalue to my project
 - for create statistic remote
'''
sonar.projectKey=polygon-backend-python                            #keyname to my project
sonar.python.coverage.reportPaths=coverage.xml                     #path to coverage.xml
sonar.language=py                                                  #lenguage params
sonar.sourceEncoding=UTF-8                                         #encoding params
sonar.qualitygate.wait=true
sonar.sources=src                                                  #path to scanning repos

My solution seems like that code. but I steel have Unittest - . looking for resolving this problem
Screenshot from 2023-04-06 11-02-02

Take a look at the documentation on test execution parameters.

1 Like

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