Skip to content
← Back to explainers

Python explainer

Choose Which Checks Block a Merge

About 5 min to read. Allow extra time to work through examples.

Split CI checks into required checks that block a merge and review signals that ask for judgment. Judge each rule by what it catches, how often it is wrong, and how clearly it tells the author what to fix.

This article uses Python. You can make it your practice mode to browse related content across the site.

Your CI runs the tests, mypy, Ruff, a coverage report and a complexity score. A pull request fails on the complexity score, and its author adds # noqa to get it merged. The check fired, and nobody learned anything. Not every check deserves the same response, so decide what each one is for before you decide whether it blocks a merge.

Required checks and review signals

A required check blocks the merge until it passes. Good candidates are the tests, the type check, the package build and the formatter. Each one needs a failure the author can reproduce on their own machine and a clear way to fix it. The formatter enforces a style. Passing it says nothing about whether the code works.

A failing test can mean a bug, a flaky test or a broken environment, so track flaky runs separately from real failures. Re-running a job until it passes hides a check that is unreliable.

A review signal points a reviewer at something that needs judgment, such as new complexity, duplicated logic, an untested branch or a module that keeps growing. Show the findings and where they are. A score from 0 to 100 can sum them up, but explain how you weight each finding, and never let an average hide one serious finding.

The same rule can play either role. Start a new rule as a review signal while you learn how often it is useful. Make it required once you know its scope, the fix it expects and how an author asks for an exception. Some risks justify blocking from the first day.

Judge a rule by what it does for you

For each candidate rule, ask:

  • What failure does it catch, and how serious is that failure?
  • How often is a finding worth acting on, and how do you know?
  • Can the author reproduce the result and fix it?
  • What important cases does it miss?
  • Who updates it when tools, dependencies or conventions change?
Check your understanding Should test coverage block a merge? Show answer

It can, if the number serves a clear testing policy. Coverage shows which lines or branches ran during the tests. It does not show that an assertion would catch a wrong result, so read the tests as well as the percentage.

Measuring only the changed lines focuses on new work. A threshold on total coverage can move for reasons a pull request did not cause, such as someone deleting well-tested code. For old code with little coverage, a baseline keeps unrelated cleanup out of every pull request. Pick a threshold from your own risks, not from another team's number.

Say what went wrong and how to fix it

Keep the rule's code, such as E722, so authors can look it up. Then explain the finding in the context of their code. A useful message for a bare except: reads:

This handler also catches KeyboardInterrupt and SystemExit. If it ignores them, Ctrl+C or an explicit exit stops working. Catch the exceptions you expect, or re-raise after any cleanup that must run.

except Exception lets those two through, but it can still hide unrelated errors, so catch only the exceptions the code knows how to handle. See Ruff's bare-except rule.

Be as exact with other findings. Python creates a mutable default argument once and shares it across calls, so if the function changes it, later calls see earlier data. That sentence explains the risk better than "mutable defaults are bad".

Count the mistakes against the right total

Check your understanding A blocking rule catches a serious bug about once a month, but someone says it is wrong 5% of the time. Should it stop blocking merges? Show answer

First ask what the 5% counts. If your team opens 40 pull requests a week and the rule wrongly blocks 5% of them, that is two wrong blocks a week. If the rule reports ten findings a month and 5% of those are wrong, that is one wrong finding every two months. Neither number tells you how many bugs the rule misses.

Then weigh how serious the bugs are, how much time a wrong block costs, and whether reviewers would act on the same finding as advice. You can fix a flaky part, narrow the rule, allow a reviewed exception or make it advice. You can also keep it required, if the risk is worth the cost. Record the decision, and check later whether it helped.

A good merge policy tells an author what a failed check means and what to do next, and it lets maintainers remove a check whose findings nobody acts on.

step 39 of 41

Modules, Packaging and Tooling

Up next Design a CI Pipeline That Tests the Release