简体   繁体   中英

Django-nose test results and coverage not being gathered and displayed in sonar

I have a django project, which is wrapped in a maven build which handles packaging and publishing, as well as generating docs and other lifecycle tasks.

We have tests that are executed in django-nose that are exectued at the test phase of the maven lifecycle.

NOSE_ARGS = [
  '--with-coverage',
  '--cover-erase',
  '--cover-package={0}'.format(TEST_FOLDERS),
  '--cover-html',
  '--cover-branches',
  '--cover-html-dir=' + COVERAGE_WORK_FOLDER + 'coverage-reports/',
  '--cover-xml',
  '--cover-xml-file=' + COVERAGE_WORK_FOLDER + 'coverage.xml',
  '--with-xunit',
  '--xunit-file=' + COVERAGE_WORK_FOLDER + 'nosetests.xml',
]

This is successfully run by maven during the test phase, outputs a coverage.xml and nosetests.xml which appears to contain valid content and are in the target folder of the build.

user@user target  cat nosetests.xml 
<?xml version="1.0" encoding="UTF-8"?><testsuite name="nosetests" tests="13" errors="2" failures="0" skip="0"><testcase classname="*snip*" name="test_a" time="0.035">

In maven, the structure is a multi-module pom, in the parent, sonar variables are configured.

<sonar.language>py</sonar.language>
<sonar.python.xunit.reportPath>${project.build.directory}/nosetests.xml</sonar.python.xunit.reportPath>
<sonar.python.coverage.reportPath>${project.build.directory}/coverage.xml</sonar.python.coverage.reportPath>
<sonar.sources>src/main/python/django</sonar.sources>
<sonar.python.xunit.skipDetails>false</sonar.python.xunit.skipDetails>

Whilst the child contains the pom that creates, packages, tests, etc.

When running mvn clean install, followed by mvn sonar:sonar -X, as far as I can see the plugin detects the nosetests and the coverage file, however when looking at sonar I can not see unit test results or coverage.

[INFO] Sensor PythonXUnitSensor
[DEBUG] Using pattern '/home/user/src/django-app/code/target/nosetests.xml' to find reports
[INFO] Sensor PythonXUnitSensor (done) | time=3492ms
[INFO] Sensor PythonCoverageSensor
[DEBUG] Using pattern '/home/user/src/django-app/code/target/coverage.xml' to find reports
[DEBUG] Parsing coverage reports
[DEBUG] Parsing integration test coverage reports
[DEBUG] Using pattern 'coverage-reports/it-coverage-*.xml' to find reports
[DEBUG] Parsing overall test coverage reports
[DEBUG] Using pattern 'coverage-reports/overall-coverage-*.xml' to find reports
[INFO] Sensor PythonCoverageSensor (done) | time=1321ms
**SNIP**
[INFO] CPD calculation finished
[INFO] Analysis report generated in 542ms, dir size=756 KB
[INFO] Analysis reports compressed in 879ms, zip size=331 KB
[DEBUG] Upload report
[DEBUG] POST 200 https://sonar.local/api/ce/submit?projectKey=com.example:django&projectName=DJANGO | time=104ms
[INFO] Analysis report uploaded in 106ms
[INFO] ANALYSIS SUCCESSFUL, you can browse https://sonar.local/dashboard/index/com.example:django
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at https://sonar.local/api/ce/task?id=AVXFLPhlOl8UXdQaHPyt
[DEBUG] Report metadata written to /home/user/src/django-app/target/sonar/report-task.txt
[DEBUG] Post-jobs : 
[INFO] Analysis report generated in /home/user/src/django-app/target/sonar/batch-report

So the source code, complexity, etc. appear but neither the unit test results (at the path above) or the coverage is displayed.

Versions:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>sonar-maven-plugin</artifactId>
  <version>3.0.1</version>
</plugin>

SonarQube: Version 5.5 Python Plugin: Version 1.5

Edit: Updated SonarQube to version 5.6, python to 1.6-SNAPSHOT

mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.1-SNAPSHOT:sonar -X -o
---
[DEBUG] Using pattern '/home/user/src/django-app/code/target/nosetests.xml' to find reports
[INFO] Processing report '/home/user/src/django-app/code/target/nosetests.xml'
[DEBUG] Trying to find a SonarQube resource for 'maven.tests.TestMavenVersionsViewSet'
[DEBUG] Using the key 'maven/tests/TestMavenVersionsViewSet.py' to lookup the resource in SonarQube
[DEBUG] Using the key 'maven/tests.py' to lookup the resource in SonarQube
[WARNING] The resource for 'maven.tests.TestMavenVersionsViewSet' is not found, drilling down to the details of this test won't be possible
[DEBUG] Trying to find a SonarQube resource for 'audit.tests.TestSortDeploys'
[DEBUG] Using the key 'audit/tests/TestSortDeploys.py' to lookup the resource in SonarQube
[DEBUG] Using the key 'audit/tests.py' to lookup the resource in SonarQube
[WARNING] The resource for 'audit.tests.TestSortDeploys' is not found, drilling down to the details of this test won't be possible
[INFO] Sensor PythonXUnitSensor (done) | time=4195ms
[INFO] Sensor SCM Sensor (wrapped)
[INFO] SCM provider for this project is: svn
[INFO] 1 files to be analyzed
[DEBUG] Working directory: /home/user/src/django-app/code
[DEBUG] Annotate file src/main/python/audit_ws/audit/tests.py
[DEBUG] File [moduleKey=internal.build.services:audit_ws-site, relative=src/main/python/audit_ws/audit/tests.py, basedir=/home/user/src/django-app/code] is not versionned or contains local modifications. Skipping it.
[INFO] 0/1 files analyzed
[WARNING] Missing blame information for the following files:
[WARNING]   * /home/user/src/django-app/code/src/main/python/audit_ws/audit/tests.py
[WARNING] This may lead to missing/broken features in SonarQube
[INFO] Sensor SCM Sensor (wrapped) (done) | time=1521ms
[INFO] Sensor Python Squid Sensor (wrapped)
[DEBUG] Metric lines is an internal metric computed by SonarQube. Provided value is ignored.
*SNIP*
[INFO] Python unit test coverage
[DEBUG] Using pattern '/home/user/src/django-app/code/target/coverage.xml' to find reports
[INFO] Parsing report '/home/user/src/django-app/code/target/coverage.xml'
[DEBUG] Cannot find the file 'lib/JiraSoap.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/admin.py', ignoring coverage measures
[DEBUG] Cannot find the file 'config_item/autocomplete_light_registry.py', ignoring coverage measures
[DEBUG] Cannot find the file 'config_item/forms.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/models.py', ignoring coverage measures
[DEBUG] Cannot find the file 'lib/productws.py', ignoring coverage measures
[DEBUG] Cannot find the file 'lib/renderers.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard/serializers.py', ignoring coverage measures
[DEBUG] Cannot find the file 'audit_ws/settings.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/tasks.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/urls.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/views.py', ignoring coverage measures
[DEBUG] Cannot find the file 'audit/management.py', ignoring coverage measures
[DEBUG] Cannot find the file 'audit/management/commands.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/templatetags.py', ignoring coverage measures
[INFO] Python integration test coverage
[DEBUG] Using pattern 'coverage-reports/it-coverage-*.xml' to find reports
[DEBUG] No report was found for sonar.python.coverage.itReportPath using default pattern coverage-reports/it-coverage-*.xml
[INFO] Python overall test coverage
[DEBUG] Using pattern 'coverage-reports/overall-coverage-*.xml' to find reports
[DEBUG] No report was found for sonar.python.coverage.overallReportPath using default pattern coverage-reports/overall-coverage-*.xml
[INFO] Sensor Python Squid Sensor (wrapped) (done) | time=3057ms
[INFO] Sensor XmlFileSensor (wrapped)
[INFO] Sensor XmlFileSensor (wrapped) (done) | time=0ms
[INFO] Sensor Zero Coverage Sensor (wrapped)
[INFO] Sensor Zero Coverage Sensor (wrapped) (done) | time=82ms
[INFO] Sensor Code Colorizer Sensor (wrapped)
[INFO] Sensor Code Colorizer Sensor (wrapped) (done) | time=3ms
[INFO] Sensor CPD Block Indexer (wrapped)
[INFO] DefaultCpdBlockIndexer is used for py
[DEBUG] Using pattern '/home/user/src/django-app/code/target/nosetests.xml' to find reports
[INFO] Processing report '/home/user/src/django-app/code/target/nosetests.xml'
[DEBUG] Trying to find a SonarQube resource for 'maven.tests.TestMavenVersionsViewSet'
[DEBUG] Using the key 'maven/tests/TestMavenVersionsViewSet.py' to lookup the resource in SonarQube
[DEBUG] Using the key 'maven/tests.py' to lookup the resource in SonarQube
[WARNING] The resource for 'maven.tests.TestMavenVersionsViewSet' is not found, drilling down to the details of this test won't be possible
[DEBUG] Trying to find a SonarQube resource for 'audit.tests.TestSortDeploys'
[DEBUG] Using the key 'audit/tests/TestSortDeploys.py' to lookup the resource in SonarQube
[DEBUG] Using the key 'audit/tests.py' to lookup the resource in SonarQube
[WARNING] The resource for 'audit.tests.TestSortDeploys' is not found, drilling down to the details of this test won't be possible
[INFO] Sensor PythonXUnitSensor (done) | time=4195ms
[INFO] Sensor SCM Sensor (wrapped)
[INFO] SCM provider for this project is: svn
[INFO] 1 files to be analyzed
[DEBUG] Working directory: /home/user/src/django-app/code
[DEBUG] Annotate file src/main/python/audit_ws/audit/tests.py
[DEBUG] File [moduleKey=internal.build.services:audit_ws-site, relative=src/main/python/audit_ws/audit/tests.py, basedir=/home/user/src/django-app/code] is not versionned or contains local modifications. Skipping it.
[INFO] 0/1 files analyzed
[WARNING] Missing blame information for the following files:
[WARNING]   * /home/user/src/django-app/code/src/main/python/audit_ws/audit/tests.py
[WARNING] This may lead to missing/broken features in SonarQube
[INFO] Sensor SCM Sensor (wrapped) (done) | time=1521ms
[INFO] Sensor Python Squid Sensor (wrapped)
[DEBUG] Metric lines is an internal metric computed by SonarQube. Provided value is ignored.
*SNIP*
[INFO] Python unit test coverage
[DEBUG] Using pattern '/home/user/src/django-app/code/target/coverage.xml' to find reports
[INFO] Parsing report '/home/user/src/django-app/code/target/coverage.xml'
[DEBUG] Cannot find the file 'lib/JiraSoap.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/admin.py', ignoring coverage measures
[DEBUG] Cannot find the file 'config_item/autocomplete_light_registry.py', ignoring coverage measures
[DEBUG] Cannot find the file 'config_item/forms.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/models.py', ignoring coverage measures
[DEBUG] Cannot find the file 'lib/productws.py', ignoring coverage measures
[DEBUG] Cannot find the file 'lib/renderers.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard/serializers.py', ignoring coverage measures
[DEBUG] Cannot find the file 'audit_ws/settings.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/tasks.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/urls.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/views.py', ignoring coverage measures
[DEBUG] Cannot find the file 'audit/management.py', ignoring coverage measures
[DEBUG] Cannot find the file 'audit/management/commands.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/templatetags.py', ignoring coverage measures
[INFO] Python integration test coverage
[DEBUG] Using pattern 'coverage-reports/it-coverage-*.xml' to find reports
[DEBUG] No report was found for sonar.python.coverage.itReportPath using default pattern coverage-reports/it-coverage-*.xml
[INFO] Python overall test coverage
[DEBUG] Using pattern 'coverage-reports/overall-coverage-*.xml' to find reports
[DEBUG] No report was found for sonar.python.coverage.overallReportPath using default pattern coverage-reports/overall-coverage-*.xml
[INFO] Sensor Python Squid Sensor (wrapped) (done) | time=3057ms
[INFO] Sensor XmlFileSensor (wrapped)
[INFO] Sensor XmlFileSensor (wrapped) (done) | time=0ms
[INFO] Sensor Zero Coverage Sensor (wrapped)
[INFO] Sensor Zero Coverage Sensor (wrapped) (done) | time=82ms
[INFO] Sensor Code Colorizer Sensor (wrapped)
[INFO] Sensor Code Colorizer Sensor (wrapped) (done) | time=3ms
[INFO] Sensor CPD Block Indexer (wrapped)
[INFO] DefaultCpdBlockIndexer is used for py
[DEBUG] Using pattern '/home/user/src/django-app/code/target/nosetests.xml' to find reports
[INFO] Processing report '/home/user/src/django-app/code/target/nosetests.xml'
[DEBUG] Trying to find a SonarQube resource for 'maven.tests.TestMavenVersionsViewSet'
[DEBUG] Using the key 'maven/tests/TestMavenVersionsViewSet.py' to lookup the resource in SonarQube
[DEBUG] Using the key 'maven/tests.py' to lookup the resource in SonarQube
[WARNING] The resource for 'maven.tests.TestMavenVersionsViewSet' is not found, drilling down to the details of this test won't be possible
[DEBUG] Trying to find a SonarQube resource for 'audit.tests.TestSortDeploys'
[DEBUG] Using the key 'audit/tests/TestSortDeploys.py' to lookup the resource in SonarQube
[DEBUG] Using the key 'audit/tests.py' to lookup the resource in SonarQube
[WARNING] The resource for 'audit.tests.TestSortDeploys' is not found, drilling down to the details of this test won't be possible
[INFO] Sensor PythonXUnitSensor (done) | time=4195ms
[INFO] Sensor SCM Sensor (wrapped)
[INFO] SCM provider for this project is: svn
[INFO] 1 files to be analyzed
[DEBUG] Working directory: /home/user/src/django-app/code
[DEBUG] Annotate file src/main/python/audit_ws/audit/tests.py
[DEBUG] File [moduleKey=internal.build.services:audit_ws-site, relative=src/main/python/audit_ws/audit/tests.py, basedir=/home/user/src/django-app/code] is not versionned or contains local modifications. Skipping it.
[INFO] 0/1 files analyzed
[WARNING] Missing blame information for the following files:
[WARNING]   * /home/user/src/django-app/code/src/main/python/audit_ws/audit/tests.py
[WARNING] This may lead to missing/broken features in SonarQube
[INFO] Sensor SCM Sensor (wrapped) (done) | time=1521ms
[INFO] Sensor Python Squid Sensor (wrapped)
[DEBUG] Metric lines is an internal metric computed by SonarQube. Provided value is ignored.
*SNIP*
[INFO] Python unit test coverage
[DEBUG] Using pattern '/home/user/src/django-app/code/target/coverage.xml' to find reports
[INFO] Parsing report '/home/user/src/django-app/code/target/coverage.xml'
[DEBUG] Cannot find the file 'lib/JiraSoap.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/admin.py', ignoring coverage measures
[DEBUG] Cannot find the file 'config_item/autocomplete_light_registry.py', ignoring coverage measures
[DEBUG] Cannot find the file 'config_item/forms.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/models.py', ignoring coverage measures
[DEBUG] Cannot find the file 'lib/productws.py', ignoring coverage measures
[DEBUG] Cannot find the file 'lib/renderers.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard/serializers.py', ignoring coverage measures
[DEBUG] Cannot find the file 'audit_ws/settings.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/tasks.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/urls.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/views.py', ignoring coverage measures
[DEBUG] Cannot find the file 'audit/management.py', ignoring coverage measures
[DEBUG] Cannot find the file 'audit/management/commands.py', ignoring coverage measures
[DEBUG] Cannot find the file 'wallboard_ws/templatetags.py', ignoring coverage measures
[INFO] Python integration test coverage
[DEBUG] Using pattern 'coverage-reports/it-coverage-*.xml' to find reports
[DEBUG] No report was found for sonar.python.coverage.itReportPath using default pattern coverage-reports/it-coverage-*.xml
[INFO] Python overall test coverage
[DEBUG] Using pattern 'coverage-reports/overall-coverage-*.xml' to find reports
[DEBUG] No report was found for sonar.python.coverage.overallReportPath using default pattern coverage-reports/overall-coverage-*.xml
[INFO] Sensor Python Squid Sensor (wrapped) (done) | time=3057ms
[INFO] Sensor XmlFileSensor (wrapped)
[INFO] Sensor XmlFileSensor (wrapped) (done) | time=0ms
[INFO] Sensor Zero Coverage Sensor (wrapped)
[INFO] Sensor Zero Coverage Sensor (wrapped) (done) | time=82ms
[INFO] Sensor Code Colorizer Sensor (wrapped)
[INFO] Sensor Code Colorizer Sensor (wrapped) (done) | time=3ms
[INFO] Sensor CPD Block Indexer (wrapped)
[INFO] DefaultCpdBlockIndexer is used for py

I have doubled checked the working directory: [INFO] Base dir: /home/user/src/django-app/code [INFO] Working dir: /home/user/src/django-app/code/target/sonar

Is it looking for the tests and coverage relative to the working directory?

Based on your logs, it seems that the report paths are provided as absolute paths. Version 1.5 of the python plugin only accepts relative paths. That's a known limitation which is going to be fixed in version 1.6. This new version is almost ready and you should be able to test a release candidate very soon. That will be announced on the SonarQube google group .

sonar.tests属性添加到您的配置中:

sonar.tests=tests_folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM