Skip to content
Latchkey

Python "pytest-cov: no data was collected" in CI

"CoverageWarning: No data was collected" means coverage.py recorded zero lines. With pytest-cov this is almost always a mismatch between the --cov target and the package actually imported, or measurement that did not follow into subprocesses.

What this error means

CI prints "CoverageWarning: No data was collected. (no-data-collected)" and the coverage report shows 0% or an empty table.

pytest
WARNING: Failed to generate report: No data to report.
/.../coverage/control.py: CoverageWarning: No data was collected. (no-data-collected)

Common causes

The --cov path does not match the imported package

Coverage targeted a source dir name that differs from the installed/imported package, so nothing was measured.

Code ran in a subprocess or xdist worker without coverage

The measured code executed in a child process that coverage did not instrument.

How to fix it

Point --cov at the real package and enable subprocess coverage

  1. Set --cov=<import_package_name> to the name actually imported, not the directory.
  2. For installed packages, prefer measuring the import name; for src layout, target the package under src.
  3. Enable concurrency/subprocess coverage if code runs in workers or child processes.
pyproject.toml
[tool.coverage.run]
source = ["mypkg"]
parallel = true
concurrency = ["multiprocessing"]

How to prevent it

  • Match --cov to the imported package name.
  • Use coverage parallel/concurrency settings for multi-process tests.
  • Run coverage locally to confirm data is collected before CI.

Related guides

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