In my Azure DevOps build pipeline I use coverage.py to report coverage on Python code tested using unittest. I create a coverage.xml file in Cobertura format and use the PublishCodeCoverageResults@1 task to upload it. I see the expected coverage results in the Code Coverage tab of my build results page in the DevOps UI after coverage.xml.
However when I reference the same coverage.xml file using the sonar.python.coverage.reportPaths property in the subsequent SonarQubePrepare@4 task, I see 0.0% coverage reported for my project in the SonarQube server!
Looking at similar issues posted here (especially this one), I wonder if it’s because the filename entries in my coverage.xml use absolute paths?
Note that to get coverage.py to report coverage correctly I had to set its
coverage run --source value to point at the python files installed under lib\site-packages on my DevOps VM. If I pointed at the checked-out source code instead I got zero coverage reported by coverage.py. I think that’s because the tests are executing against the installed code rather than the source code.
Does anyone know how I can get SonarQube to show the coverage results in coverage.xml please?