Skip to content
Latchkey

SonarScanner "Coverage report could not be read" in CI

The scanner found the coverage report you pointed it at but could not parse it, or could not map its file paths to indexed sources. Coverage ends up at 0% even though tests ran.

What this error means

The scan log shows "Coverage report 'coverage.xml' could not be read" or "cannot resolve the file path ... of the coverage report", and new-code coverage reads 0%.

sonar-scanner
WARN: Could not resolve 43 file paths in [coverage.xml]
ERROR: Coverage report 'coverage.xml' could not be read/imported.

Common causes

The report is empty or malformed

Tests failed to write a full report, or the file is truncated, so the parser cannot read it.

Report paths do not match indexed sources

The coverage tool wrote absolute or container paths that do not line up with the files Sonar indexed, so it cannot map coverage to source.

How to fix it

Generate a valid report with relative paths

  1. Run the coverage tool so it writes an XML report with project-relative paths.
  2. Confirm the report is non-empty before the scanner runs.
  3. Set the correct report path property for your language.
Terminal
pytest --cov=src --cov-report=xml
sonar-scanner -Dsonar.python.coverage.reportPaths=coverage.xml

Exclude files that should not count toward coverage

Use coverage exclusions for generated or non-testable files so they do not distort or break import.

sonar-project.properties
sonar.coverage.exclusions=**/migrations/**,**/__init__.py

How to prevent it

  • Produce coverage with relative paths that match indexed sources.
  • Verify the report is generated before the scanner step.
  • Use sonar.coverage.exclusions for files that should not be measured.

Frequently asked questions

What causes ""Coverage report ... could not be read""?
Tests failed to write a full report, or the file is truncated, so the parser cannot read it.
How do I fix "Coverage report ... could not be read"?
Generate a valid report with relative paths

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card