Invalid Coverage report

Hello,

I’ve been having an issue recently with the Coverage report for a python script. It produces the report itself using the following command:

pytest \
  --html=test-report/unit/result-report.html \
  --cov-report xml:./test-report/unit/coverage-report.xml \
  --cov=./ \
  test.py

This is my sonar-project.properties file:

#Coverage Exclusions
sonar.coverage.exclusions=test.py

#Duplicate Code Exclusions
sonar.cpd.exclusions=test.py

#Issues exclusions
sonar.exclusions=**/*.html,Dockerfile,*.txt,*.sh,*.json,*.md,*.properties

sonar.coverage.jacoco.xmlReportPaths=test-report/unit/coverage-report.xml

And finally this is the error I get in when I run the sonnar-scanner

ERROR: Coverage report '/home/jenkins/agent/workspace/olympus-hades-ingestion/Olympus Hades Ingestion - branch push/test-report/unit/coverage-report.xml' could not be read/imported. Error: {}
java.lang.IllegalStateException: Invalid report: expected to find 'line' within a 'sourcefile' at line 14 column 7
	at org.sonar.plugins.jacoco.XmlReportParser.parse(XmlReportParser.java:89)
	at org.sonar.plugins.jacoco.JacocoSensor.importReport(JacocoSensor.java:70)
	at org.sonar.plugins.jacoco.JacocoSensor.importReports(JacocoSensor.java:62)
	at org.sonar.plugins.jacoco.JacocoSensor.execute(JacocoSensor.java:47)
	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:62)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:75)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:48)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:66)
	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:48)
	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:64)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:446)
	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:442)
	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:400)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:128)
	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:123)
	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:109)
	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:58)
	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:52)
	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
	at com.sun.proxy.$Proxy0.execute(Unknown Source)
	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
	at org.sonarsource.scanner.cli.Main.main(Main.java:61)

I can share the file generated if necessary, although I haven’t seen anything strange there

Hi,

Welcome to the community!

There are several things going on here:

  • Your project is Python
  • You’re generating a pytest report
  • You’re importing the pytest report by telling analysis it’s a JaCoCo report

The error you’re getting is saying that what you’ve passed as a JaCoCo report… isn’t a valid JaCoCo report (because it’s a pytest report). Additionally, per the docs Cobertura is what’s supported for Python, not pytest.

The options I see:

 
HTH,
Ann

Hello Ann,

Thank you very much for your reply and the links.
Actually the solution was quite simple and in the direction you mentioned.
I just needed to replace sonar.coverage.jacoco.xmlReportPaths
by sonar.python.coverage.reportPaths in the sonar-project.properties files.

The fact that I created this report with pytest seems to be still fine.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.