[英]SonarQube does not correctly import coverage.xml file for Python project
I'm working on a Python project on Linux.我正在研究 Linux 上的 Python 项目。
I'm trying to link the coverage.xml
report to SonarQube analysis.我正在尝试将
coverage.xml
报告链接到 SonarQube 分析。
The project structure is the following:项目结构如下:
- root
- folder1
...
- folder2
...
- ...
- coverage.xml
I run the SonarScanner analysis with the following command:我使用以下命令运行 SonarScanner 分析:
sonar-scanner \
-Dsonar.projectKey=test \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=xxxxxxxx \
-Dsonar.python.coverage.reportPaths=coverage.xml
Everything works fine except the coverage that it's always not considered.除了始终不考虑的覆盖范围外,一切正常。
Here the console output:这里是控制台 output:
INFO: Python test coverage
INFO: Parsing report '/my/path/coverage.xml'
INFO: Sensor Cobertura Sensor for Python coverage [python] (done) | time=73ms
INFO: Sensor PythonXUnitSensor [python]
INFO: Sensor PythonXUnitSensor [python] (done) | time=13ms
INFO: Sensor SonarCSS Rules [cssfamily]
INFO: No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=2ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: 'sonar.coverage.jacoco.xmlReportPaths' is not defined. Using default locations:
target/site/jacoco/jacoco.xml,target/site/jacoco-
it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
INFO: No report imported, no coverage information will be imported by JaCoCo XML Report Importer
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=9ms
INFO: Sensor JavaXmlSensor [java]
INFO: 1 source files to be analyzed
INFO: Sensor JavaXmlSensor [java] (done) | time=306ms
INFO: 1/1 source files have been analyzed
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=5ms
INFO: Sensor XML Sensor [xml]
INFO: 1 source files to be analyzed
INFO: Sensor XML Sensor [xml] (done) | time=257ms
INFO: 1/1 source files have been analyzed
INFO: ------------- Run sensors on project
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=12ms
INFO: CPD Executor 21 files had no CPD blocks
INFO: CPD Executor Calculating CPD for 21 files
INFO: CPD Executor CPD calculation finished (done) | time=31ms
INFO: Analysis report generated in 86ms, dir size=397 KB
INFO: Analysis report compressed in 140ms, zip size=133 KB
INFO: Analysis report uploaded in 18ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=test
What am I doing wrong?我究竟做错了什么?
I faced the same issue.我遇到了同样的问题。 The problem is with coverage.xml file.
问题在于coverage.xml 文件。 The xml file generated by pytest was incorrect with respect to source path.
由 pytest 生成的 xml 文件的源路径不正确。 Because of which the SonarQube was not able to reach the source files and bring the coverage data.
因此,SonarQube 无法访问源文件并带来覆盖数据。 To solve the problem you can once check the source path in xml file and manually update it.
要解决此问题,您可以检查 xml 文件中的源路径并手动更新它。 There is another solution to use coverage library which will fix the xml for us.
还有另一种使用覆盖库的解决方案,它将为我们修复 xml。
But It did not worked for me.但它对我不起作用。 Still I will add it here.
我还是会在这里添加它。
Install coverage安装覆盖
pip3 install coverage
Run跑
python3 -m coverage xml -i
in the directory where xml is kept.在保存 xml 的目录中。 It should Fix the source path.
它应该修复源路径。 But In my case It was deleting the xml file itself.
但就我而言,它正在删除 xml 文件本身。 So, I updated source manually and SonarQube was able to show the coverage.
因此,我手动更新了源代码,SonarQube 能够显示覆盖范围。 But It is not possible to change source manually.
但是无法手动更改源。
To automate it We can use自动化它我们可以使用
python3 -m coverage xml -i
Hopefully It will help.希望它会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.