简体   繁体   English

如何在SonarQube中获取python单元测试结果?

[英]How to get python unit test results in SonarQube?

I'm using SonarQube 4.5. 我正在使用SonarQube 4.5。 I've run nosetests to run python unit tests and create an xunit xml file called nosetests.xml. 我已经运行过鼻子测试以运行python单元测试,并创建了一个称为鼻子测试.xml的xunit xml文件。 I'm running Sonar Runner via the Sonar Jenkins plugin. 我正在通过Sonar Jenkins插件运行Sonar Runner。 I've set the following Sonar properties: 我设置了以下Sonar属性:

sonar.projectKey=yauis
sonar.projectName=YAUIS
sonar.projectVersion=1.0
sonar.sources=src
sonar.language=py
sonar.python.xunit.reportPath=nosetests.xml
sonar.python.pylint=/usr/bin/pylint
sonar.python.coverage.reportPath=coverage.xml
sonar.python.coveragePlugin=cobertura

I'm seeing the following in the SonarQube Runner log: 我在SonarQube Runner日志中看到以下内容:

...
15:31:20.355 INFO  - Sensor PythonXunitSensor...
15:31:20.363 INFO  - Processing report '/var/lib/jenkins/jobs/yauis/workspace/nosetests.xml'
15:31:20.363 INFO  - Parsing report '/var/lib/jenkins/jobs/yauis/workspace/nosetests.xml'
15:31:20.480 INFO  - Sensor PythonXunitSensor done: 125 ms
...

Here is a snippet from nosetests.xml: 这是nosetests.xml的片段:

<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="nosetests" tests="30" errors="30" failures="0" skip="0">
    <testcase classname="nose.failure.Failure" name="runTest" time="0.000">
        <error type="exceptions.ImportError" message="cannot import name get_data_parameter&#xA;-------------------- &gt;&gt; begin captured logging &lt;&lt; --------------------&#xA;py.warnings: WARNING: /var/lib/jenkins/jobs/yauis/workspace/.pyenv/local/lib/python2.7/site-packages/rest_framework/fields.py:686: DeprecationWarning: The `blank` keyword argument is deprecated. Use the `required` keyword argument instead.&#xA;  super(DateTimeField, self).__init__(*args, **kwargs)&#xA;&#xA;py.warnings: WARNING: /var/lib/jenkins/jobs/yauis/workspace/.pyenv/local/lib/python2.7/site-packages/rest_framework/fields.py:465: DeprecationWarning: The `blank` keyword argument is deprecated. Use the `required` keyword argument instead.&#xA;  super(CharField, self).__init__(*args, **kwargs)&#xA;&#xA;py.warnings: WARNING: /var/lib/jenkins/jobs/yauis/workspace/.pyenv/local/lib/python2.7/site-packages/cassandra/cqltypes.py:63: UserWarning: The blist library is not available, so a normal set will be used in place of blist.sortedset for set collection values. You can find the blist library here: https://pypi.python.org/pypi/blist/&#xA;  &quot;The blist library is not available, so a normal set will &quot;&#xA;&#xA;--------------------- &gt;&gt; end captured logging &lt;&lt; ---------------------"><![CDATA[File "/usr/lib/python2.7/unittest/case.py", line 327, in run
    testMethod()
  File "/var/lib/jenkins/jobs/yauis/workspace/.pyenv/local/lib/python2.7/site-packages/nose/loader.py", line 414, in loadTestsFromName
    addr.filename, addr.module)
  File "/var/lib/jenkins/jobs/yauis/workspace/.pyenv/local/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/var/lib/jenkins/jobs/yauis/workspace/.pyenv/local/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/var/lib/jenkins/jobs/yauis/workspace/src/adminapi/urls.py", line 8, in <module>
    from views import AdminApiViewHandler
  File "/var/lib/jenkins/jobs/yauis/workspace/src/adminapi/views.py", line 9, in <module>
    from common.ViewUtils import json_response, get_data_parameter
  File "/var/lib/jenkins/jobs/yauis/workspace/src/common/ViewUtils.py", line 13, in <module>
    from common.utils import get_application_uri
  File "/var/lib/jenkins/jobs/yauis/workspace/src/common/utils.py", line 550, in <module>
    from common.managers.formfactormanager import FormfactorModifier
  File "/var/lib/jenkins/jobs/yauis/workspace/src/common/managers/formfactormanager.py", line 3, in <module>
    from common.ViewUtils import get_data_parameter
'cannot import name get_data_parameter\n-------------------- >> begin captured logging << --------------------\npy.warnings: WARNING: /var/lib/jenkins/jobs/yauis/workspace/.pyenv/local/lib/python2.7/site-packages/rest_framework/fields.py:686: DeprecationWarning: The `blank` keyword argument is deprecated. Use the `required` keyword argument instead.\n  super(DateTimeField, self).__init__(*args, **kwargs)\n\npy.warnings: WARNING: /var/lib/jenkins/jobs/yauis/workspace/.pyenv/local/lib/python2.7/site-packages/rest_framework/fields.py:465: DeprecationWarning: The `blank` keyword argument is deprecated. Use the `required` keyword argument instead.\n  super(CharField, self).__init__(*args, **kwargs)\n\npy.warnings: WARNING: /var/lib/jenkins/jobs/yauis/workspace/.pyenv/local/lib/python2.7/site-packages/cassandra/cqltypes.py:63: UserWarning: The blist library is not available, so a normal set will be used in place of blist.sortedset for set collection values. You can find the blist library here: https://pypi.python.org/pypi/blist/\n  "The blist library is not available, so a normal set will "\n\n--------------------- >> end captured logging << ---------------------']]></error>
    </testcase>
...

The unit test results are not showing in SonarQube. SonarQube中未显示单元测试结果。 What am I missing? 我想念什么?

This is a known issues with SonarQube 4.2+ that has been fixed but not released yet: SONARPY-37 这是SonarQube 4.2+的一个已知问题,已修复,但尚未发布: SONARPY-37

You should stay tuned and wait for version 1.4 of the Python plugin. 您应该继续关注并等待Python插件的1.4版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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