Skip to content

Repository files navigation

test-amnesty — CI stays green. The bugs don't.

CI Python 3.11+ MIT license

Recorded demo: a one-cent bug passes pytest, then test-amnesty detects the weakened test

Give weakened tests amnesty. Keep the evidence.

test-amnesty spots three kinds of pytest changes, restores the original test in a temporary copy, and runs both versions against the same head implementation. When the original fails and the edited test passes, you get a reproducible review finding.

Replay with asciinema play docs/assets/demo.cast. The GIF is rendered from that recording.

15-second Quickstart

From a clone of this repository, inside a Python 3.11+ virtual environment:

python -m pip install -e .
bash scripts/run_demo.sh

For your own repository, install its test dependencies in the same environment, then:

test-amnesty scan --repo /path/to/repo --base HEAD~1 --head HEAD

Read test-amnesty-report.md; retain test-amnesty-report.json for the evidence. The demo checks the expected finding and exits successfully.

The problem in one picture

Strict test fails against the same broken code that the weakened test accepts

The fixture discounts 1,001 cents by 25%. Its original contract rounds down to 750. A change to round() returns 751. Widening the test tolerance lets the extra cent through.

02  Broken implementation + weakened test
    round(750.75) returns 751; the new test allows a one-cent error.
1 passed

03  test-amnesty scan --base <strict-commit> --head HEAD
test-amnesty: 1 confirmed, 0 not confirmed, 0 inconclusive
    Original test against broken head: FAIL (751 != 750)
    Edited test against broken head:   PASS

Explore the exact fixture or run the demo script. This is an intentionally constructed regression, not a claim about a real package.

Three detected patterns

Pattern Structural trigger Example
REMOVED_ASSERT A base assertion disappears from the entire head test module. Delete assert result() == 7.
RELAXED_TOLERANCE Matching integer equality becomes an absolute tolerance, or that tolerance increases. result() == 7 becomes abs(result() - 7) <= 1.
ADDED_MOCK An exact supported mock call and target appears in the edited function. Add monkeypatch.setattr("module.value", 7).

Recognized mock call names: unittest.mock.patch, mock.patch, mocker.patch, and monkeypatch.setattr. Aliases and keyword-only target arguments are unsupported. An assertion moved to a helper in the same file is excluded from removed-assert detection.

What a result means

Result Meaning Scan exit
Clean No confirmed or inconclusive supported candidates. 0
Confirmed Original test fails an assertion; edited test passes against the same head. 1
Input error Arguments, refs, files, reports, or configuration are invalid. 2
Inconclusive Collection, setup, execution, skip, or timeout prevents reliable evidence. 3

Input errors take precedence, followed by inconclusive results, then confirmed findings. Both tests passing or both failing produces not_confirmed evidence and exit 0 unless another candidate has a stronger result.

A finding describes the whole test function. If it contains several edits, this release does not prove which edit caused the difference. Intentional specification changes can legitimately invalidate old assertions. A maintainer makes that call. Single runs can also be affected by flaky tests or external state.

GitHub Actions

Install your project's test dependencies for Python 3.11 before using the action. The action installs test-amnesty and appends its report to the job summary.

name: Test amnesty
on: [pull_request]
permissions:
  contents: read
jobs:
  evidence:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          persist-credentials: false
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - run: python -m pip install -e '.[test]'
      - uses: 0xABCD01/test-amnesty@v0.1.0
        with:
          base: ${{ github.event.pull_request.base.sha }}
          head: ${{ github.event.pull_request.head.sha }}
          timeout: '60'

Replace the dependency-install command with your project's actual command. Run repository code only in an environment suitable for executing that code; temporary exports are not a security sandbox. Keep credentials out of test jobs and use pull_request, never privileged pull_request_target, for this example.

CLI

test-amnesty scan --base REF --head HEAD --repo . \
  --json test-amnesty-report.json --markdown test-amnesty-report.md --timeout 60
test-amnesty render test-amnesty-report.json --output -
test-amnesty --version

--base is required. Other scan arguments above show their defaults. Use - for one output destination to write it to stdout. Status goes to stderr. Each pytest process has its own timeout. Reports keep the final 8,192 output characters. The report contract is in evidence.schema.json.

Where it fits

Tool Question answered How
test-amnesty Did a supported test edit lose detection against this head implementation? Replay original and edited functions against identical head exports.
Stryker Does a test suite catch injected faults? Mutate production code and measure which mutations survive.

Scope of v0.1.0

Linux first; Python 3.11+; pytest only. Tests must be changed top-level synchronous test_* functions in unchanged-path test_*.py or *_test.py files. Function names, parameters, defaults, annotations, and decorators must match between revisions. Existing head imports, helpers, fixtures, and project configuration are retained. Dirty and untracked local content is not included. Dependencies must already exist.

Do not expect class or async tests, renames, changed signatures, cross-file helper analysis, automatic installs, mutation generation, LLM calls, source patches, PR comments, coverage scoring, a hosted service, Windows guarantees, submodules, Git LFS expansion, or non-UTF-8 source. A clean scan is not a repository-wide quality verdict.

Built in the open

The project ideas, build specification, and implementation decisions document the AI-assisted workflow. This implementation was produced with Codex. CLAUDE.md and AGENTS.md provide instructions for future maintenance; their presence is not evidence of a Claude run. Neither OSS program's acceptance is claimed.

Want a small first contribution? Submit a weakened-test fixture. See contributing and the code of conduct.

Releases

Packages

Contributors

Languages