python 运行信息,将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

All test files are in test folder.

nosetests.xml is xml report generated with nose(tests) (1.3.7).

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

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.

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.

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.

解决方案

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.

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 .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值