Skip to content
Latchkey

pytest-cov "No data was collected" / module-not-measured in CI

coverage.py recorded no data: the --cov target did not match the imported package, the code was already imported before coverage started, or tests ran against an installed copy instead of the source tree.

What this error means

The run warns "CoverageWarning: No data was collected. (no-data-collected)" or "Module X was never imported," and total coverage shows 0% or the report is empty.

pytest-cov
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

Passing --cov=mypackage while tests import an installed copy from site-packages means coverage watches a path no code runs in.

The package was imported before coverage started

Importing the package at collection time, or via a conftest, can load it before measurement begins, so lines are not counted.

How to fix it

Point --cov at the actual source and install editable

  1. Install the project editable so tests import the source tree, not a built copy.
  2. Set --cov to the import name or src path that tests actually load.
  3. Re-run and confirm coverage is non-zero.
Terminal
pip install -e .
pytest --cov=src --cov-report=term

Measure with the source layout in config

Declare the source in .coveragerc so coverage maps the installed package back to your source files.

.coveragerc
# .coveragerc
[run]
source = src
relative_files = true

How to prevent it

  • Install the project editable in CI so imports hit the source tree.
  • Match --cov/source to the package tests import.
  • Avoid importing the package before coverage starts.

Related guides

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