Python sonar不收集测试

0 投票
1 回答
1174 浏览
提问于 2025-04-18 13:59

我在配置文件里写了这些内容:

sonar.sources=dev
sonar.python.xunit.reportPath=parts/jenkins-test/testreports/*.xml
sonar.dynamicAnalysis=reuseReports

我看到的测试xml文件是junit格式的(jenkins也能正确处理这些文件)。

当我运行 sonar-runner 时,我看到:

23:26:54.094 INFO  - Processing report '..././parts/jenkins-test/testreports/widget.tests.test_widget.TestLookup.xml'
23:26:54.094 INFO  - Parsing report '..././parts/jenkins-test/testreports/widget.tests.test_widget.TestLookup.xml'
2

但是在sonar的仪表盘上我看不到任何测试结果。我使用的是sonar 4.3版本和runner 2.4版本。

更新

如果我用 --debug 参数运行 sonar-runner,我在日志里看到:

09:53:29.619 INFO  - Parsing report '..././parts/jenkins-test/testreports/md.authentication.tests.test_tokenauth.TestTokenAuthenticatorTestCase.xml'
09:53:29.620 DEBUG - Cannot find the resource for authentication.tests.test_tokenauth.TestTokenAuthenticatorTestCase, creating a virtual one
09:53:29.620 DEBUG - Saving test execution measures for file 'authentication.tests.test_tokenauth.TestTokenAuthenticatorTestCase' under resource 'org.sonar.api.resources.File@4336db7c[key=<null>,deprecatedKey=authentication.tests.test_tokenauth.TestTokenAuthenticatorTestCase,path=<null>,dir=<null>,filename=authentication.tests.test_tokenauth.TestTokenAuthenticatorTestCase,language=Python]'

1 个回答

1

这些是认证相关的测试,还是Python的包?是在Unix系统上吗?

你可以看看这里可能相关的内容:http://sonarqube.15.x6.nabble.com/Python-coverage-information-not-showing-up-in-Sonar-td5005729.html

顺便说一下,我也遇到同样的问题,可以显示测试覆盖率,但无法显示单元测试的统计数据...

查看PythonXunitSensor的代码,似乎它在寻找

authentication/tests/test_tokenauth.py时失败了,可能需要检查一下这个SonarQube的工作目录路径。

祝好,

拉斐尔。

撰写回答