← Insights

How to Check a Pull Request for Missing or Weak Tests

Set up a CI check that flags pull requests with untested production changes, uncovered lines or weak new assertions, and why a green build is not enough.

13 min read
How to Check a Pull Request for Missing or Weak Tests

A pull request can pass every test in CI and still change behavior nobody tested. To catch that automatically, run a check on each pull request that reads the diff, asks whether the tests around the change moved with it, and tells the reviewer where to look. PR Test Guard, a Tigerless Labs project, does this for Python repositories. It is advisory by default, needs no API key and no language model on its default path, and is MIT licensed. This article walks through six of its signals, with a starter workflow you can copy into a new repository and a worked example you can run yourself.

The check gives a reviewer a place to start. It does not decide whether the code is correct. It also does not replace the review, and a team that reads every line of every pull request may not need a second signal at all, as the last section explains.

Any luck automating QA on Pull Requests?

Yes, if the check runs on every pull request, reads the same diff the reviewer reads, and reports where the review already happens. The question comes from this r/azuredevops thread, where the poster has waited a long time for a QA project and wants the rules defined and run. The answer depends on whether a machine can apply those rules to every change, instead of a person noticing missing tests by hand.

A reviewer asks three questions of each pull request: did production code change without a test change, did the new lines run under a test, and do the new tests assert anything? Each question has a mechanical signal, and automation can compute all three. The first comes from the diff. The second needs a coverage report. The third reads the assertions the pull request adds.

Set up the workflow in a new repository

The starter workflow works in a new repository with no configuration and no coverage report. Save it as .github/workflows/pr-test-guard.yml and commit it on a branch. It leaves out config on purpose. Without a configuration file, PR Test Guard uses its built-in defaults: every rule is a warning, nothing blocks a merge, and no paths are ignored. The first pull request then shows you what the defaults find in your own code, before you decide anything.

name: PR Test Guard

on:
  pull_request:

permissions:
  contents: read

jobs:
  pr-test-guard:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: tigerless-labs/pr-test-guard@v0.8.0
        with:
          base: origin/${{ github.base_ref }}

Then follow these steps:

  1. Commit the workflow file on a branch and open a pull request that changes some Python code.
  2. Keep the full history in the checkout, which the fetch-depth setting does, so the base branch is there to compare against.
  3. Open the Checks tab of the pull request and read the PR Test Guard job, as described below.
  4. Leave every rule advisory until you agree with its findings on your own code.

Add a configuration file when the defaults are not enough

When the defaults do not fit, commit a configuration file named .pr-test-guard.yml at the root of the repository. This one keeps PTG001 and PTG002 as warnings and ignores findings under docs/. PTG001 flags production Python that changed without a test change. PTG002 flags changed lines that no test runs.

# .pr-test-guard.yml
rules:
  PTG001: warn
  PTG002: warn
paths:
  ignore:
    - "docs/**"

Each rule takes one of three levels. off hides the rule. warn reports its findings as advice that never fails the job. error reports them and fails the job when they fire. A team usually starts with warn everywhere, then moves one rule at a time to error once it trusts that rule's findings on its own code.

PR Test Guard finds this file at the repository root on its own, so the config line is optional. Add it under the Action's with: block when you want the path written out, or when the file lives somewhere else: config: .pr-test-guard.yml. Commit the file and the workflow change in the same pull request.

A configuration error stops the job with exit code 2, and the message names the problem. A misspelled value, such as PTG002: warnn, produces rules.PTG002 must be one of: off, warn, error.

Show the untested lines with coverage

PTG002 needs a coverage.py XML report. The Action does not run your tests or measure coverage, so the workflow runs the tests first, writes coverage.xml, and passes the file to the coverage input. Run the tests and PR Test Guard on the same checkout. The workflow below uses GitHub's test merge commit by default, so the report describes the merged code the diff would produce. This workflow is for a pytest project. Replace the install line with the one your repository already uses.

name: PR Test Guard

on:
  pull_request:

permissions:
  contents: read

jobs:
  pr-test-guard:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"

      - name: Run tests and write coverage.xml
        run: |
          python -m pip install -e . pytest pytest-cov
          pytest --cov=. --cov-report=xml

      - uses: tigerless-labs/pr-test-guard@v0.8.0
        with:
          base: origin/${{ github.base_ref }}
          coverage: coverage.xml

Use --cov=. rather than a package name such as --cov=src. The report stores file paths relative to the directory it measured, and PR Test Guard matches those paths against the repository's paths. In our test, --cov=src wrote pricing.py where the repository has src/pricing.py. The coverage rule found no match, so the untested line produced no finding. With --cov=., the path is src/pricing.py and the finding appears. If a line you know is untested never shows up, open coverage.xml and check its paths first.

If a test fails, the job stops at the test step and the PR Test Guard step does not run, so read the test failure first.

Read the result from the Checks tab

Open the pull request and choose the Checks tab. Select PR Test Guard and open the job. The job summary holds one table per rule, with severity, location, signal and evidence. Each location gives a file and a line. Find that line in the pull request's Files changed view and read it against the diff. The evidence column tells you what the rule saw: for PTG002 it quotes the line itself, and for PTG007 it lists the change unit and the number of tests that reach it.

The job summary ends with a footer. It reads "Configured policy failed because at least one error-level rule triggered." when an error-level rule fired, and "No error-level policy triggered. Warning findings remain advisory." when none did.

A warning is advice, and the job passes. A rule set to error that triggers makes the job fail. A configuration error or a missing coverage file also fails the job, with exit code 2. Whether a failed job stops the merge is a GitHub setting, covered in the FAQ below.

Most first runs find something, and that is the point of the first few pull requests. Treat each finding as a question for the author: is the line untested on purpose, does the test file need one more case, or is the rule wrong for this code? Answer it in the pull request conversation. Change the configuration only when the same finding keeps coming up for reasons the team agrees with.

Try it on your own machine first

Install the same version from a clone, using Python 3.11 or later: git clone --branch v0.8.0 https://github.com/tigerless-labs/pr-test-guard.git, then python3 -m pip install -e ./pr-test-guard. Run the check inside your project's Git repository, with pr-test-guard check --base origin/main --coverage coverage.xml. The local run prints the same findings in plain text and changes nothing on GitHub, so you can try it on a branch that is not pushed yet.

Are pull requests dead in the age of agentic coding?

No. The question is fair when an agent writes the diff: the reviewer then judges code they did not write, and line-by-line reading gets harder as the diff grows. The question is asked in this r/ClaudeCode thread, where the poster pushes back on the idea that teams should ship without review. A pull request is still the one place where the change, its tests and CI meet, so a check there does the most good exactly when the diff is large.

Agents work from the instructions and skills they are given. autoharness is Tigerless Labs' project for Claude Code skills that update from real sessions. It does not check pull requests, and a pull-request check does not replace it.

Why doesn't a green test run answer the question?

Because a passing run answers a different question. The test runner says whether the current tests passed. A coverage report says which lines were executed. PR Test Guard asks whether the pull request shows obvious test-quality risks. A green run does not tell you whether the changed behavior was tested well.

Coverage is one of the signals, not the verdict. A changed line can run under a test that asserts nothing useful, or under a mock that replaces the behavior under review. The coverage.py documentation on dynamic contexts describes contexts as the way to record which test was running when each line executed. The pytest-cov contexts page documents the same contexts for pytest runs.

A reviewer who sees an uncovered line should not ask the author to cover everything. The useful question is narrower: which behavior does this line add, and would a test that fails when that behavior breaks protect it? Sometimes the answer is a new test. Sometimes the line is error handling that only a rare input reaches, and the author should say so in the pull request.

A worked example: a negative amount returns zero

This is a local demonstration built for this article. It is not taken from the project's repository or its issues. We ran it with PR Test Guard v0.8.0 in a scratch repository, and each output below is what the tool printed.

The base branch has one function, and its one test checks a positive amount with a 20 percent discount. The pull request changes the function so that a negative amount returns zero:

# src/pricing.py, changed
def apply_discount(amount, rate):
    if amount < 0:
        return 0
    return amount * (1 - rate)

The author also adds a second positive test, a 10 percent discount on 50, which is assert apply_discount(50, 0.1) == 45. With that test added, pytest reports 2 passed, and the build is green. The test file changed, so the rule that asks for a test change has nothing to say. Coverage tells a different story. No test sends a negative amount, so the return 0 line never runs. The coverage report records that line with zero hits:

<line number="3" hits="0"/>

Run the tests with pytest --cov=. --cov-report=xml, then pr-test-guard check --base main --coverage coverage.xml --format text. The tool turns that line into a finding:

PTG002 (1 warning)
  [WARN] src/pricing.py:3
  Changed executable line is not covered by the supplied coverage report.
  Evidence: return 0

Covering the line is not the same as testing it. A tempting fix is a test that calls the function with a negative amount and checks only that some value came back:

def test_negative_amount():
    result = apply_discount(-5, 0.2)
    assert result is not None

The test passes, and the line now runs, so PTG002 disappears. The test still accepts any answer, including a wrong one. PTG003 flags the shape of the assertion instead:

PTG003 (1 warning)
  [WARN] tests/test_pricing.py:14

The assertion that matches the rule checks the value the rule promises:

def test_negative_amount():
    result = apply_discount(-5, 0.2)
    assert result == 0

After that change, pytest reports 3 passed, and both PTG002 and PTG003 are gone. PTG007 stays in every version of this demonstration. It asks whether the changed function has test evidence along its call path, which this article does not cover. Read it as a question for the reviewer, not a verdict.

What do these six signals check?

These are PTG001 to PTG006, the rules the project's public description covers. Each one answers a question a reviewer already asks.

RuleWhat it flags
PTG001Production Python changed, and the pull request has no test-file change
PTG002A changed Python line is uncovered in the supplied coverage XML
PTG003A newly added assertion has an obviously weak existence or truthiness shape
PTG004A test was deleted, skipped or marked xfail, or lost assertions
PTG005A mock directly replaces a changed symbol, or a changed test mocks an unconstrained internal dependency called on a changed line
PTG006An opt-in bounded targeted probe survives the configured tests

Each repository sets each rule to off, warn or error in its .pr-test-guard.yml. For an enabled rule, policy.fail_on makes a matching finding fail the check. Rules set to off stay disabled. Out of the box the check is advisory: a successful analysis exits 0 even when it finds something. Findings are review signals, not proof that a pull request is right or wrong.

How the deeper check works

PTG006 belongs to the deeper check, which is opt-in. It needs the project's own test command. The tool runs in isolated Git worktrees, verifies the unmodified tests first, then applies a bounded number of probes, and --max-probes caps them:

pr-test-guard check --base origin/main --deep --test-command "pytest -q" --max-probes 3

Deep mode assumes the workflow has already installed the repository's test dependencies and that the test command passes before the tool runs. In the GitHub Action the same switches are inputs named deep, test-command and max-probes. Put the deep run in its own job, or on the pull requests that need it, so the default check stays quick. Keep it separate for a practical reason as well: each probe runs your test command again, so the deep job takes as long as several test runs together.

When is a test-quality check the wrong tool?

Doing nothing wins when the pull request is small, the author is the only reviewer, and every change is already read line by line. A second signal then adds noise. A team that treats each finding as a verdict will spend time on false alarms, so keep the check advisory and let people judge.

A rival wins outside Python. The rules follow Python and pytest conventions by default, and the product page describes no other language. A repository in another language needs a tool built for it. A repository that already gates changed-line coverage in CI and reads its tests gets less from a second coverage signal. The assertion and mock rules, PTG003 to PTG005, are the part a coverage gate does not inspect, so that is where a second check adds the most.

For a similar approach in another area, the seo-ops project runs deterministic checks on a site's structure and reports the evidence for each failure.

Conclusion

The answer is to automate the three questions a reviewer asks: did production code change without tests, do the changed lines run, and do the new assertions check anything. A workflow on each pull request does this from the same diff the reviewer reads, and it tells the reviewer where to look without deciding for them.

The best check is the one your team reads on every pull request and keeps advisory until it has earned a block. Turn a rule into an error only after you have read its findings on your own pull requests and agree with them.

For a next step, open a pull request you already have, run pr-test-guard check --base origin/main from a checkout, and read the findings beside the diff. The PR Test Guard page has the rules and the workflow, and the rest of Tigerless's writing is on the Insights page. Tigerless also runs its own AI in production, Lara, and publishes the engineering around it in Labs.

FAQ

Does PR Test Guard block a merge by default?

No. A warning is advice: the job passes and nothing is blocked. A triggered error rule fails the check, and so does a configuration error or a missing coverage file, which exits with code 2. Whether a failed check blocks a merge is a GitHub setting: it blocks merging only when the target branch or an applicable ruleset requires that check to pass.

Does PR Test Guard need an API key or a language model?

No. The default path needs no API key and no language model. The deeper check runs your own test command, so the repository's test dependencies must already be installed.

Do I need a coverage report to use it?

No. Without a coverage file, PTG002 is skipped and the ordinary diff checks still run. The deeper check runs only when you turn it on with the deep option and a test command. A coverage file that is given but missing or malformed is an input error: the tool exits with code 2 and the job fails. Generate the report with pytest-cov, and check that its paths match the repository's paths, as the workflow above explains.

Which languages does it check?

Python. Its rules follow Python and pytest conventions by default. Other test layouts can be added in the config, such as spec/** or **/*_spec.py under the tests include list.

Can I stop it from checking folders that are not tests?

Yes. paths.ignore hides findings for matching paths, and paths.tests.exclude keeps matching files from being counted as tests, which takes precedence over the built-in conventions.

Share this article

Keep reading