Python Test Coverage With Azure Devops pipeline

I have tried to follow the guideline (Python Test Coverage | SonarCloud Docs) to set up the coverage test in azure pipeline but the coverage is still 0%

I saw below error message and google for a long time but still can not fix it…

WARN: No report was found for sonar.python.coverage.reportPaths using pattern coverage.xml
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=19ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=9ms
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=4ms
INFO: Sensor JavaScript inside YAML analysis [javascript]
INFO: Deploying custom rules bundle jar:file:/home/vsts/.sonar/cache/ce591e3f7610860294db52053899e90f/sonar-securityjsfrontend-plugin.jar!/js-vulnerabilities-rules-1.0.0.tgz to /home/vsts/work/1/s/.scannerwork/.sonartmp/eslint-bridge-bundle/package/custom-rules3024934604809391150
INFO: 1 source file to be analyzed

I have tried to see other public code scan as a reference but seems like that most of them do not have the yml file or ini file. So I am interested is there any other way to set up the coverage for code scan - python


Welcome to the community!

How are you providing your coverage report to analysis?


Hii, thanks for asking!

I am following the sonarcloud official sample to set up but I think that is with github and for my case, I am using azure devops so there may have some difference ?

Below is the structure of my code~
Since I am not sure where to put the file. so I have tried to put it in the root and also inside tests folder

I have tried to change the content of the Tox.ini refer to the SonarCloud Docs but still can not… =(
Do I need to change the my_project to other text?

my build.yml file
do I need to fillin the Github/SonarToken ?


Analysis won’t automatically pick up your coverage report. You need to feed it in. The docs should help.


Sorry I am not too sure what you mean, you mean we need to define a place for export report ?
I thought the properties file has defined the report path ==> create coverage.xml in the root


So, the error from the OP correlates to the path you’re providing in

So the question is, where is the coverage.xml file, relative to where analysis is launched from? Is it in the directory you’re in before you invoke the SonarScanner?


Hii, the result xml file is stored in root

and I have changed the name of the output file in the pipeline but seems like sonarcloud can not get it

It has result when I change to
coverage run -m pytest
coverage xml

thanks a lot

1 Like

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