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%.
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
- Run the coverage tool so it writes an XML report with project-relative paths.
- Confirm the report is non-empty before the scanner runs.
- Set the correct report path property for your language.
pytest --cov=src --cov-report=xml
sonar-scanner -Dsonar.python.coverage.reportPaths=coverage.xmlExclude 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.coverage.exclusions=**/migrations/**,**/__init__.pyHow to prevent it
- Produce coverage with relative paths that match indexed sources.
- Verify the report is generated before the scanner step.
- Use
sonar.coverage.exclusionsfor files that should not be measured.