Number of unit test using nosetests is not reflecting in sonar report for python codebase

1.1k Views Asked by At

I am trying to get test coverage report and unit test details (number of test cases, # of passed test cases) into sonar.

I have generated report using coverage and nosetests plugin and stored same into coverage.xml and nosetests.xml

My sonar.properties file looks like

sonar.projectKey=python
sonar.projectName=Python
sonar.projectVersion=1.0
sonar.sources=vmturbo
sonar.tests=tests
sonar.language=py
sonar.sourceEncoding=UTF-8
sonar.python.xunit.reportPath=nosetests.xml
sonar.python.coverage.reportPath=coverage.xml

While running sonar-runner I am getting below message in log

0:29:51.022 INFO  - Processing report '/Users/deepeshjain/Development/Python/CD/python-distribution/nosetests.xml'
00:29:51.027 WARN  - The resource for 'vmturbo_unit_tests.Test' is not found, drilling down to the details of this test won't be possible
00:29:51.027 INFO  - Sensor PythonXUnitSensor (done) | time=115ms
00:29:51.027 INFO  - Sensor SCM Sensor
00:29:51.050 INFO  - Sensor SCM Sensor (done) | time=23ms
00:29:51.051 INFO  - Sensor Python Squid Sensor
00:29:51.221 INFO  - Python unit test coverage
00:29:51.223 INFO  - Parsing report '/Users/deepeshjain/Development/Python/CD/python-distribution/coverage.xml'
00:29:51.229 INFO  - Python integration test coverage
00:29:51.232 INFO  - Python overall test coverage
00:29:51.234 INFO  - Sensor Python Squid Sensor (done) | time=183ms

I am able to get test coverage report on sonar but not able to get the number of unit test cases for same.

1

There are 1 best solutions below

2
On

After trying multiple options, Adding test case path to nosetests.xml worked for me.

sed -i 's/classname="/classname="tests./g' nosetests.xml