Python code coverage not picked up

Must-share information (formatted with Markdown):

  • SonarQube
  • Show coverage information on the sonarqube project page
  • tried tox.ini, sed inside github actions, running sonar-scanner from local machine

My Python API’s coverage information is not coming up on SonarQube. I tried everything possible

Below are the commands i run to generate the coverage report

coverage run -m pytest tests
coverage xml

coverage.xml is generated but the sonar scanner logs says it cannot find the file.

Below is the sonar properties file

sonar.projectKey=test

sonar.projectVersion=1.0.1

# Comma-separated paths to directories containing your source code.

sonar.sources=app

# Comma-separated paths to directories containing your tests.

sonar.tests=tests

# Language specific settings for Python

sonar.language=py

sonar.python.version=3.10

sonar.python.coverage.reportPaths=coverage.xml 

# Additional optional properties

sonar.sourceEncoding=UTF-8

sonar.exclusions=**/*.xml,**/*.json,**/venv/**,patch/taaco.py # Optional: Exclude specific files or directories from analysis

Below is the sonar log

INFO: Scanner configuration file: /Users/anees/sonar-scanner/conf/sonar-scanner.properties
INFO: Project root configuration file: /Users/anees/Code/MHE/dle-ai-detection-api/sonar-project.properties
INFO: SonarScanner 5.0.1.3006
INFO: Java 17.0.7 Eclipse Adoptium (64-bit)
INFO: Mac OS X 13.5.1 x86_64
INFO: User cache: /Users/anees/.sonar/cache
INFO: Analyzing on SonarQube server 9.2.4
INFO: Default locale: "en_IN", source code encoding: "UTF-8"
INFO: Load global settings
INFO: Load global settings (done) | time=1238ms
INFO: Server id: E5B28E3B-AXTWMyVnr8ZHQBcSopsF
INFO: User cache: /Users/anees/.sonar/cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=333ms
INFO: Load/download plugins (done) | time=438ms
INFO: Process project properties
INFO: Process project properties (done) | time=8ms
INFO: Execute project builders
INFO: Execute project builders (done) | time=2ms
INFO: Project key: dle-ai-detection-api
INFO: Base dir: /Users/anees/Code/MHE/dle-ai-detection-api
INFO: Working dir: /Users/anees/Code/MHE/dle-ai-detection-api/.scannerwork
INFO: Load project settings for component key: 'dle-ai-detection-api'
INFO: Load project settings for component key: 'dle-ai-detection-api' (done) | time=288ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=326ms
INFO: Load active rules
INFO: Load active rules (done) | time=7527ms
INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: **/*.xml, **/*.json, **/venv/**, patch/taaco.py  # Optional: Exclude specific files or directories from analysis
INFO: 35 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: Quality profile for py: Sonar way
INFO: ------------- Run sensors on module dle-ai-detection-api
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=300ms
INFO: Sensor Python Sensor [python]
INFO: Starting global symbols computation
INFO: 12 source files to be analyzed
INFO: Load project repositories
INFO: Load project repositories (done) | time=326ms
INFO: 12/12 source files have been analyzed
INFO: Starting rules execution
INFO: 12 source files to be analyzed
INFO: 12/12 source files have been analyzed
INFO: Starting test sources highlighting
INFO: 4 source files to be analyzed
INFO: 4/4 source files have been analyzed
INFO: Sensor Python Sensor [python] (done) | time=2378ms
INFO: Sensor Cobertura Sensor for Python coverage [python]
WARN: No report was found for sonar.python.coverage.reportPaths using pattern coverage.xml  # Optional: Path to coverage report
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=4150ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=1852ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
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
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=3ms
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=0ms
INFO: Sensor C# Project Type Information [csharp]
INFO: Sensor C# Project Type Information [csharp] (done) | time=1ms
INFO: Sensor C# Analysis Log [csharp]
INFO: Sensor C# Analysis Log [csharp] (done) | time=17ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=1ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=3ms
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=17ms
INFO: Sensor VB.NET Properties [vbnet]
INFO: Sensor VB.NET Properties [vbnet] (done) | time=0ms
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=15ms
INFO: SCM Publisher is disabled
INFO: CPD Executor 1 file had no CPD blocks
INFO: CPD Executor Calculating CPD for 11 files
INFO: CPD Executor CPD calculation finished (done) | time=13ms
INFO: Analysis report generated in 65ms, dir size=170.6 kB
INFO: Analysis report compressed in 76ms, zip size=52.1 kB
INFO: Analysis report uploaded in 890ms
INFO: ANALYSIS SUCCESSFUL, you can browse https://sonarqube.mgmt.prod.mheducation.com/connect/dashboard?id=dle-ai-detection-api
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 https://sonarqube.mgmt.prod.mheducation.com/connect/api/ce/task?id=AYpqiRHfZ-0QdtpeEKbN
INFO: Analysis total time: 19.465 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 23.282s
INFO: Final Memory: 9M/60M
INFO: ------------------------------------------------------------------------

Hi,

Your version is past EOL. You should upgrade to either the latest version or the current LTS at your earliest convenience. Your upgrade path is:

9.2.4 → 9.9.2 → 10.2 (last step optional)

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

If your error persists after upgrade, please come back to us.