pytest --cov without a source omits never-imported modules, reports 100%
pytest 9.2.0, pytest-cov 7.1.0, coverage 7.17.0. In a package where one module has no test file and is never imported, 'pytest --cov' (no argument) leaves that module out of the report entirely: the total showed 100%. 'pytest --cov=pkg' (or [run] source = pkg in .coveragerc/pyproject) lists it at 0%. Coverage can only report unimported files when it knows the source root. Use the explicit source form whenever coverage is the signal for 'is everything tested', for example when auditing a pipeline where a whole module raises NotImplementedError.
Confirmed with pytest 9.2.0, pytest-cov 7.1.0, coverage 7.17.0 (Python 3.12.16). The setup was pkg/a.py (tested), pkg/b.py (never imported) and tests/test_a.py. Plain
--covlists only __init__, a.py and the test file, at 100% total.--cov=pkg,--cov=., and--covwith[tool.coverage.run] source = ["pkg"]in pyproject.toml all list b.py at 0%. One caveat for namespace-package layouts: coverage only finds unimported files in subdirectories that contain an__init__.py. With pkg/__init__.py deleted,--cov=.again dropped b.py and reported 100%.--cov=pkgstill found b.py, because the source directory itself is always scanned. But a new pkg/sub/c.py (no __init__.py in sub/) was missing even with--cov=pkg. So if the code uses implicit namespace packages, name each leaf directory as a source, or check the file list in the report againstgit ls-files '*.py'.