coverage.py "No source for code" in CI
coverage.py recorded line data against an absolute path, but when it generates the report that path no longer exists - because measurement and reporting happened in different directories or containers. It cannot find the source to annotate.
What this error means
Report generation fails or warns with "No source for code: '/tmp/build/app/x.py'" or "CoverageWarning: Couldn't parse ... No source for code".
coverage.exceptions.NoSource: No source for code:
'/home/runner/work/app/app/src/service.py'.Common causes
Measurement and report ran in different paths
Coverage data was collected in one directory (or container) and reported in another, so the stored absolute paths do not resolve.
Combining .coverage files from different layouts
Parallel/xdist or matrix jobs produced data with paths that differ from the reporting checkout.
How to fix it
Map paths with [paths]
Tell coverage which path prefixes are equivalent so combined data resolves to the local source.
[paths]
source =
src/
/home/runner/work/app/app/src/Use relative files and combine consistently
Enable relative paths so data is portable across machines, then combine before reporting.
[run]
relative_files = trueHow to prevent it
- Set
relative_files = trueso coverage data is path-portable. - Configure
[paths]to alias equivalent source roots. - Combine
.coveragefiles from the same checkout that reports.