mrkeyoor.com_
Sun 20 Sept 07:02 UTC
PyPITestingupdated 20 Sept 2026

pytest-cov review

pytest-cov 7.1.0 is the pytest adapter for coverage.py. It starts measurement with the test session, merges worker data, erases or appends coverage files, labels execution by test context, writes terminal and machine-readable reports, and can fail CI below a percentage. Coverage.py remains the measurement engine and owns most configuration. Version 7.1.0 fixes a serious CI inconsistency where report choices could change the total used by `--cov-fail-under`; it also corrects matching of escaped sqlite3 ResourceWarning filters.

Verdict

pytest-cov 7.1.0 installed in 0.4 seconds and occupied 9 MB across 7 packages in our sandbox, with 0 audit findings. Add it when pytest should own coverage reporting and worker data; configure coverage.py explicitly for subprocesses and treat the percentage as a regression check, not a score for test quality.

We installed it

Lab card: what happened when we installed pytest-covScreenshot of pytest-cov documentation
Install✓ · 0.4s7 packages on disk · 9 MB
Importimport pytest_cov in 0.55s · pure Python · requires Python >=3.9
Known vulns0(pip-audit)

Answers from our run

Does pytest-cov install cleanly?

Yes. In a fresh container with an empty cache, pip install pytest-cov finished in 0.4s, leaving 7 packages and 9 MB on disk. pip-audit reported no known vulnerabilities.

What does pytest-cov need to run?

Python >=3.9, and nothing compiled: it is pure Python. In our run import pytest_cov succeeded in 0.55s.

pytest-cov or coverage: which should you use?

coverage: Use coverage.py directly when pytest does not own the process or plugin behavior is unnecessary. pytest-cov 7.1.0 installed in 0.4 seconds and occupied 9 MB across 7 packages in our sandbox, with 0 audit findings.

When should you not use pytest-cov?

Tests run through unittest or another entry point; coverage.py can execute them without a pytest plugin

API stability4/5The main flags for source selection, report formats, branch coverage, contexts, appending, and thresholds remain established. Version 7 intentionally removes automatic child-process startup and requires the coverage.py patch setting instead. Version 7.1.0 then repairs total computation across reporting choices. A 6.x to 7.x upgrade therefore needs a subprocess audit even when the ordinary pytest command looks unchanged.
Docs5/5The official documentation separates configuration, reports, xdist, subprocess support, contexts, tox, debuggers, and plugin coverage. Its upgrade section gives the exact `[run] patch = subprocess` replacement for the removed .pth file, and the configuration page explains which pytest flags override coverage.py settings. The 7.1 changelog names the threshold calculation bug and links it to reporting options.
Maintenance4/5GitHub reported an unarchived repository pushed on 2026-04-24 with 170 open issues and pull requests. Version 7.1.0 shipped on 2026-03-21 with a correctness fix for total coverage and better sqlite3 warning-filter handling. Maintenance follows both pytest and coverage.py releases, which keeps the adapter current but also means failures can originate in either upstream project or their interaction.
Ecosystem5/5The measured weekly count was 54,220,385 downloads, and GitHub showed 2,056 stars. pytest, coverage.py, and pytest-xdist form its working ecosystem, while CI services understand XML and LCOV output. The package deliberately adds coordination rather than another measurement engine, which keeps its role clear for pytest suites and gives non-pytest projects little reason to install it.

Use it if

  • A pytest command should produce terminal, HTML, XML, JSON, LCOV, or Markdown coverage output
  • CI needs one reproducible coverage floor shared with local pytest runs
  • pytest-xdist workers must contribute execution data to the same final report
  • Per-test contexts are needed to identify which test reaches a particular line
Skip it if

Setup reality

Our Python 3.12 sandbox installed pytest-cov 7.1.0 in 0.4 seconds. Seven packages occupied 9 MB, and pip-audit found 0 known vulnerabilities. Inspection found 6 direct dependencies, pure Python code, an MIT License, and a Python 3.9 minimum. import pytest_cov completed in 0.55 seconds. The distribution did not include py.typed. pytest and coverage.py arrive as runtime requirements.

No credentials are needed. Keep measurement policy in .coveragerc, pyproject.toml, setup.cfg, or tox.ini, then use a short pytest command. --cov=package replaces coverage.py's configured source selection; a bare --cov keeps those sources. Pass --cov-config for a nonstandard filename, especially when workers or subprocesses start from another directory. Decide branch mode and omit rules in the same file used by CI.

pytest-cov 7 removed the .pth file that used to begin measurement in child interpreters. Projects that spawn Python now enable coverage.py's subprocess patch under [run]; parallel data settings may also be necessary. pytest-xdist remains supported, including remote workers, but pytest-cov and compatible coverage.py versions must be installed in every worker environment. Non-Python child programs and native extension internals remain outside this measurement model.

A normal run erases existing coverage data before tests. Use --cov-append only when separate commands are intentionally combined. Adding XML or HTML reports can remove the default terminal report unless term or term-missing is also requested. --cov-context=test stores full pytest node IDs, including parametrized cases, and can enlarge the data file. Version 7.1.0 should be the minimum for a threshold gate because 7.0 report combinations could calculate different totals.

Patterns

Measure one import package measure-package

pytest --cov=myapp --cov-report=term-missing

A named `--cov` value overrides coverage.py source configuration. Use bare `--cov` to preserve configured sources.

Fail CI below 90 percent fail-threshold

pytest --cov=myapp --cov-fail-under=90

Version 7.1.0 fixes the total calculation that could change when a different report combination was selected.

Record branch as well as statement execution measure-branches

pytest --cov=myapp --cov-branch --cov-report=term-missing

Branch mode checks decision outcomes and usually reports a lower figure than statement-only measurement.

Write terminal details and an XML artifact write-multiple-reports

pytest --cov=myapp --cov-report=term-missing --cov-report=xml:coverage.xml

Request `term` or `term-missing` explicitly when adding another report and terminal output is still required.

Start coverage in child Python interpreters configure-subprocesses

# .coveragerc
[run]
patch = subprocess
parallel = true

pytest-cov 7 no longer injects automatic subprocess startup. The coverage.py patch setting now controls it.

Merge execution from xdist workers run-with-xdist

pytest -n auto --cov=myapp --cov-report=xml

Every local or remote worker needs compatible pytest-cov and coverage.py installations.

Associate covered lines with pytest node IDs record-test-contexts

pytest --cov=myapp --cov-context=test

Parametrized node IDs are stored as contexts and can make the coverage database much larger.

Combine unit and integration runs deliberately append-runs

pytest tests/unit --cov=myapp
pytest tests/integration --cov=myapp --cov-append
coverage report

Without `--cov-append`, the second command erases coverage left by the first.

Select a nonstandard coverage configuration use-config-file

pytest --cov --cov-config=config/coverage.ini

An explicit path prevents discovery from changing when a worker or child interpreter starts elsewhere.

Build a browsable line-by-line report generate-html

pytest --cov=myapp --cov-report=html:coverage-html

HTML is convenient for local inspection. CI integrations more often consume XML, JSON, or LCOV.

Exclude generated and migration files omit-generated-code

# .coveragerc
[run]
source = myapp
branch = true

[report]
omit =
    */migrations/*
    myapp/generated/*

Keep omit rules in the shared coverage configuration so local and CI commands calculate the same denominator.

List uncovered line numbers in the terminal show-missing-lines

pytest --cov --cov-report=term-missing:skip-covered

The `skip-covered` suffix hides files at 100 percent and keeps the terminal report focused on remaining gaps.

Alternatives

PackageRegistryPick it when
coveragePyPIUse coverage.py directly when pytest does not own the process or plugin behavior is unnecessary.
noxPyPIUse it to coordinate test and coverage commands across several Python environments.
pytest-xdistPyPIUse it for parallel pytest execution when a coverage report is not part of the requirement.

More testing guides

pytest · chai · vitest · jsdom · playwright · coverage · the whole shelf →

How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.