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
- Set
--cov=<import_package_name>to the name actually imported, not the directory. - For installed packages, prefer measuring the import name; for src layout, target the package under src.
- 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
Python "responses library: no match for registered URL" in CIFix "ConnectionError: Connection refused by Responses ... no match for URL" in CI - the responses library int…
Python "tox: ERROR could not install deps" in CIFix "ERROR: could not install deps" in tox in CI - tox failed to install the dependencies for an environment,…
pytest-cov Reports 0% / "module-not-imported" - No Source MeasuredFix pytest-cov measuring nothing in CI - "--cov" set to the wrong path, an editable/installed package measure…