I'm running a pretty simple set of python projects through sonar-runner and am having issues getting tests to show up.
I'm running Sonar 3.2.1, with Python Plugin 1.1. The coverage report is generated previously.
I have the following set:
sonar.dynamicAnalysis=reuseReports
sonar.core.codeCoveragePlugin=cobertura
sonar.python.coverage.reportPath=coverage.xml
No matter what I do at this point, the coverage does not show up.
My tests are in the same folder as my sources... could that be the issue? Is there a requirement for how source code is laid out for the coverage report to get analayzed properly by sonar?
Edit: Adding a few more notes...
The coverage widget shows up but shows:
Code coverage
-
Unit test success
0 tests
I'm also seeing when I run sonar-runner:
10:04:29.641 INFO p.PhasesTimeProfiler - Sensor PythonCoverageSensor...
10:04:29.642 INFO .p.c.CoberturaParser - Parsing report '/home/jenkins/jobs/myproject/workspace/trunk/src/python/coverage.xml'
10:04:29.883 INFO p.PhasesTimeProfiler - Sensor PythonCoverageSensor done: 242 ms
Also had this issue, and pytest was not producing a properly formatted coverage report what sonarqube could utilize. I ran coverage xml -i
after pytest produced the coverage report, and this command produces a properly formatted coverage report which sonarqube understands.
I was running into a similar issue where python test coverage was not reflected in the SonarQube. The issue happens when coverage.xml has the incorrect path to the source files and SonarQube fails to find those source files when parsing the xml report.
There is an open bug for the same issue on coveragepy: https://github.com/nedbat/coveragepy/issues/578 and a workaround https://github.com/LibraryOfCongress/concordia/pull/857 . However, this workaround didn't work for me.
What I ended up doing: after running my test command (python -m pytest -m unit) that generates coverage.xml with wrong path, I ran coverage xml -i . It overwrites the previous coverage.xml and has the correct paths to source files.
Now the SonarQube has the coverage information.
"sonar.python.coverage.reportPath" must point to the path of the coverage file relative to the "sonar-project.properties" file. Generally, those temporary files are generated in temp folder like "target" or "bin". So your configuration should more look like:
sonar.python.coverage.reportPath=target/coverage.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With