将python测试运行信息导入sonarqube [英] Importing python test run information into sonarqube

查看:478
本文介绍了将python测试运行信息导入sonarqube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有这样结构的python项目,我正在尝试将其导入SonarQube:

I have a python project with structure like this and I'm trying to import it into SonarQube:

root
    sonar-project.properties
    src
    test
        nosetests.xml

所有测试文件都在测试文件夹中. nasetests.xml是使用鼻子(测试)(1.3.7)生成的xml报告.

All test files are in test folder. nosetests.xml is xml report generated with nose(tests) (1.3.7).

我的sonar-scanner.properties文件看起来像这样

My sonar-scanner.properties file looks like this

sonar.projectKey=python-sonar
sonar.projectName=python-sonar
sonar.projectVersion=1.0
sonar.sources=src
sonar.tests=test
sonar.language=py
sonar.sourceEncoding=UTF-8
#I want the details so this is false.
sonar.python.xunit.skipDetails=false
sonar.python.xunit.reportPath=test/nosetests.xml
sonar.python.coverage.itReportPath=test/cover.xml

当尝试将项目导入SonarQube时,所有测试都出现以下错误,并且没有将测试信息导入SonarQube.

When trying to import project into SonarQube I get following error for all the tests and no test information is import into SonarQube.

WARN: The resource for 'unittests.testcase' is not found, drilling down to the details of this test won't be possible.

深入研究细节,我发现问题在于PythonXUnitSensor在反映测试用例名称的路径上寻找测试文件.例如,测试位于路径test/unitests/testcase上,并且如果它在XML报告中的名称为test.unitests.testcase,则将其导入.但是鼻子测试将其命名为unitests.testcase,因此不会被导入.

Digging into details I found out the problem is that PythonXUnitSensor looks for test files on path that reflects test case name. For example test lies at path test/unitests/testcase and if it has name test.unitests.testcase in XML report it is imported. However nosetests names it unitests.testcase so it doesn't get imported.

我正在寻找一种干净的方法来解决此问题,以便可以在CI中使用它并重新使用它.我不想编辑报告,我在寻找一种可以正确生成报告或以原样导入报告的方法.

I am looking for a clean way how to solve this so it can be use in CI and reused. I don't want to edit reports, I'm looking for a way to generate them properly or to import them the way they are.

推荐答案

这似乎最好在 nosetest 级别解决,即获取 nosetests.xml 报告完全限定的路径.这样一来,SonarPython(以及其他工具)就可以正确地进行匹配了.

This seems best addressed at the nosetest level i.e. getting nosetests.xml to report the fully qualified path. That will let SonarPython (and potentially other tools) do the matching properly.

一种简单的方法:在 test 下添加一个空的__init__.py,然后重新运行测试.这将使 test 成为类路径的一部分,并且 nosetests.xml 应该在test.unitests.testcase上报告.

Simple approach to that: add an empty __init__.py under test and rerun your tests. That'll make test part of the classpath, and nosetests.xml should report on test.unitests.testcase .

这篇关于将python测试运行信息导入sonarqube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆