Skip to content

Coverage collection breaks when reorganizing tests into nested subdirectories #735

@EwoutH

Description

@EwoutH

Over at Mesa we encountered a strange issue:

pytest-cov stopped collecting coverage data after reorganizing tests from a flat package structure into nested subdirectories even though the test discovery and execution worked perfectly. See mesa/mesa#2994 for the exact changes (only test file renames).

I tried about everything, but couldn't get it fixed with pytest-cov. Switching to coverage fixed it immediately (so we did that for now mesa/mesa#3005). I still would like to get to the root cause. Below some details.

What happens:

  • All 379 tests are discovered ✅
  • All 379 tests run successfully ✅
  • pytest-cov reports: "No data was collected. (no-data-collected)" ❌
  • coverage.py itself shows the warning, suggesting it ran but didn't trace anything

Environment:

  • pytest-cov 7.0.0
  • coverage 7.13.0
  • Python 3.14.2
  • pytest 9.0.2

Workaround:
Using coverage run -m pytest instead of pytest --cov works correctly
and reports 82% coverage as expected.

Configuration:

[tool.coverage.run]
source = ["mesa"]
branch = true
omit = ["tests/*"]
relative_files = true

Questions:

  1. Is this a known limitation of pytest-cov with nested test packages?
  2. Should pytest-cov detect this and provide a clearer error message?
  3. Is there a configuration option we're missing that would make this work?

The cryptic "no data collected" error gave no hints about what changed or
how to fix it. Given that test reorganization into subdirectories is a
common refactoring, better diagnostics would be valuable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions