Skip to content
Latchkey

How to Enforce Coverage on the Diff Only in CI

Codecov patch status measures coverage of only the lines a PR changed, so new code must be tested.

Set coverage.status.patch in codecov.yml. The patch check passes only when the changed lines meet the target, independent of the whole-project number.

Steps

  • Enable coverage.status.patch in codecov.yml.
  • Set a target for the changed lines (e.g. 80%).
  • Add the patch status to required checks to block undertested PRs.

codecov.yml

codecov.yml
coverage:
  status:
    patch:
      default:
        target: 80%
        threshold: 0%
        only_pulls: true

Gotchas

  • Patch coverage needs the base commit report; make sure the base branch also uploads coverage.
  • Tools like diff-cover offer a CI-only alternative that reads the git diff plus an XML report.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →