【问题标题】:Django-nose test results and coverage not being gathered and displayed in sonarDjango-nose 测试结果和覆盖率未在声纳中收集和显示
【发布时间】:2016-11-11 01:47:57
【问题描述】:

我有一个 django 项目,它封装在一个 maven 构建中,该构建处理打包和发布,以及生成文档和其他生命周期任务。

我们有在 django-nose 中执行的测试,这些测试在 maven 生命周期的测试阶段执行。

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',
]

这在测试阶段由maven成功运行,输出一个coverage.xml和nosetests.xml,它们似乎包含有效内容并且位于构建的目标文件夹中。

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">

在maven中,结构是多模块pom,在parent中,配置了sonar变量。

<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>

虽然子进程包含创建、打包、测试等的 pom。

当运行 mvn clean install 时,接着是 mvn sonar:sonar -X,据我所见,插件检测到了鼻子测试和覆盖文件,但是在查看声纳时,我看不到单元测试结果或覆盖率。

[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

所以出现了源代码、复杂度等,但单元测试结果(在上面的路径中)或覆盖率都没有显示。

版本:

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

SonarQube:5.5 版 Python 插件:1.5 版

编辑:将 SonarQube 更新到 5.6 版,将 python 更新到 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

我已经仔细检查了工作目录: [信息] 基本目录:/home/user/src/django-app/code [INFO] 工作目录:/home/user/src/django-app/code/target/sonar

它是否在寻找与工作目录相关的测试和覆盖范围?

【问题讨论】:

    标签: python django maven sonarqube code-coverage


    【解决方案1】:

    根据您的日志,报告路径似乎是作为绝对路径提供的。 1.5 版的 python 插件只接受相对路径。 这是一个known limitation,将在 1.6 版中修复。这个新版本几乎准备就绪,您应该能够很快测试一个候选版本。这将在SonarQube google group 上公布。

    【讨论】:

    • 我编译了 python 插件的 1.6-SNAPSHOT 并将其安装到声纳中,以及 sonar-maven-plugin 的最新快照。似乎仍然存在路径问题。
    • 现在可以找到报表,但是无法解析报表中的文件路径。它们必须相对于项目的根目录。
    【解决方案2】:

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

    sonar.tests=tests_folder
    

    【讨论】:

      猜你喜欢
      • 2015-07-24
      • 2013-10-14
      • 2014-04-09
      • 2016-11-10
      • 2015-05-15
      • 2021-01-25
      • 2016-11-18
      • 2013-11-21
      • 2016-03-27
      相关资源
      最近更新 更多