Skip to content
Latchkey

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".

python
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.

.coveragerc
[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.

.coveragerc
[run]
relative_files = true

How to prevent it

  • Set relative_files = true so coverage data is path-portable.
  • Configure [paths] to alias equivalent source roots.
  • Combine .coverage files from the same checkout that reports.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →