SonarCloud Cannot Import Coverage Report

I’m facing a persistent issue with SonarCloud failing to import my Python coverage report (backend/coverage.xml) in a GitHub Actions workflow for my FastAPI project (noobsquad). The errors are:

The following error(s) occurred while trying to import coverage report:
Invalid directory path in 'source' element: /home/runner/work/noobsquad/noobsquad/backend
Cannot resolve the file path 'main.py' of the coverage report, the file does not exist in all 'source'.
Cannot resolve 38 file paths, ignoring coverage measures for those files

This results in 0% coverage in SonarCloud, despite tests running successfully and generating backend/coverage.xml. I’ve tried multiple approaches to fix the paths, but the issue persists. I’d appreciate any help!

My project structure (Simplified)

noobsquad/
├── backend/
│ ├── main.py
│ ├── api/
│ │ └── v1/
│ │ └── endpoints/
│ │ └── auth.py
│ ├── tests/
│ │ └── test_auth.py
│ └── requirements.txt
├── frontend/
├── sonar-project.properties
├── .coveragerc
└── .github/
└── workflows/
└── sonarcloud.yml

Hi,

Welcome to the community!

The paths in the coverage report need to match the paths analysis is seeing.

From what I’m reading, coverage.xml lives side-by-side with main.py, so that main.py relative file path should be correct based on the relative position of the two files.

However, analysis is running from noobsquad, right? Which means the path analysis sees is backend/main.py.

Can you make the report come out with paths relative to the project root and try again?

 
Ann

1 Like

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