Python code coverage shows 0%

I am having an issue where SonarQube shows 0% code coverage for my Python project.

- SonarQube: 7.9.3
- Sonar server platform: OpenShift 3.11
- Python version: 3.6.8
- SonarScanner
- Java 11.0.8 N/A (64-bit)
- Mac OS X 10.15.6 x86_64

I am using pytest to run the tests, currently I have 163 tests, all passed. I use the Python coverage package to generate an HTML report for easier visualization, and it reports 81% coverage. However, when I run sonar-scanner it says that it successfully parses the report.xml file yet still shows 0% code coverage on the server.

Here is my file:


I added the -X flag to sonar-scanner to output a more detailed log, I have the full output saved but here are what I consider the relevant lines (full log file attached):

DEBUG: Using pattern 'tests/*.xml' to find reports
INFO: Python test coverage
INFO: Parsing report '/Users/mitchellmurphy/Developer/SpatheSystems/brandi-flaskql/tests/report.xml'
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=126ms

sonar-debug.log (63.7 KB)

I figured it out. Pretty dumb on my behalf, pytest generates a different type of report than that SQ expects, after running pytest I also had to run coverage xml



That’s great you managed to load your Python coverage data into SonarQube. I take the opportunity of this discussion to tell you that to get the best Python analysis, it’s recommended to use the latest version of SonarQube (8.4 as of now) which always comes with the latest version of the Python analyzer. With your SQ 7.9.3 you don’t have access to the dozen of new rules and enhancements added in the analyzer itself.