AI-powered CLI to automatically fix failing tests — non-interactive, pipeable, CI-ready
Project description
testfix
AI-powered failing test auto-fixer. Run your tests, let the AI fix the failures, repeat until green — all from one command.
pip install testfix
testfix pytest # run, fix, retry up to 5× until tests pass
Supports pytest · jest · vitest · go test · cargo test
Why testfix?
You've been there: you write a feature, run tests, and see 5 failures. Fixing each one manually means reading tracebacks, understanding what broke, writing a fix, re-running — and repeating. testfix automates that loop.
Unlike GitHub Copilot (needs IDE) or aider (interactive session), testfix is a pure CLI tool: non-interactive, pipeable, pre-push hook-ready.
Installation
pip install testfix
Requires Python 3.9+. No configuration needed — just install and run.
API Keys
Set one of these (or use Ollama for free local inference):
export ANTHROPIC_API_KEY=sk-ant-... # Claude (default)
export OPENAI_API_KEY=sk-... # OpenAI
# or use --provider ollama (no key needed, runs locally)
Quick Start
# Run pytest and fix failures (up to 5 tries)
testfix pytest
# Fix a specific test file
testfix pytest tests/test_auth.py
# Run once: test → fix → test again
testfix --once pytest
# Preview fixes without applying them
testfix --dry-run pytest
# Use OpenAI instead of Claude
testfix --provider openai pytest
# Use local Ollama (free, no API key)
testfix --provider ollama pytest
# Use Jest
testfix npm test
# Use Go test
testfix go test ./...
# Focus on a specific source file
testfix --file src/auth.py pytest
How it works
testfix pytest
│
├─ Attempt 1/5
│ ├─ Run: pytest
│ ├─ 3 failing tests found
│ ├─ 🤖 Asking Claude to fix 3 failure(s)…
│ ├─ Generated 1 file fix(es)
│ │ └─ src/auth.py (diff shown)
│ └─ ✔ Applied fix (backup: .testfix.bak)
│
├─ Attempt 2/5
│ ├─ Run: pytest
│ └─ ✅ All tests pass!
│
└─ Exit 0
- Run your tests with the command you provide
- Parse failures: extracts test name, location, error, traceback
- Collect relevant source files (from tracebacks + heuristics)
- Ask the AI to fix the source code — never modifies test files
- Apply the fix (with
.testfix.bakbackup) - Repeat until tests pass or
--max-triesis reached
Options
testfix [OPTIONS] TEST_COMMAND...
Options:
--max-tries N Max fix-and-retry iterations (default: 5)
--once Run once: test → fix → test again (--max-tries 2)
--dry-run Show diffs but don't apply fixes
--provider NAME LLM provider: claude, openai, ollama (default: claude)
--model NAME Model override (e.g. claude-sonnet-4-5, gpt-4o)
--file PATH Focus fixes on this source file
-v, --verbose Show full test runner stderr
--version Show version and exit
Pre-push hook
Add to .git/hooks/pre-push:
#!/bin/bash
testfix --once --provider ollama pytest
This runs tests, lets AI fix any failures, and blocks the push if tests are still failing.
CI / GitHub Actions
- name: Run and auto-fix tests
run: testfix pytest
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
Or use --dry-run in CI to just report what would be fixed without changing files:
- name: Check if AI can fix test failures
run: testfix --dry-run pytest || echo "Tests failing (see diff above)"
Supported test frameworks
| Framework | Command example |
|---|---|
| pytest | testfix pytest |
| jest | testfix npx jest |
| vitest | testfix npx vitest |
| go test | testfix go test ./... |
| cargo test | testfix cargo test |
| rspec | testfix bundle exec rspec |
| any | testfix <your test command> |
Ecosystem
testfix is part of a suite of AI-powered developer CLI tools:
| Tool | Purpose |
|---|---|
| critiq | AI code reviewer — catch issues before you push |
| testfix | AI test fixer — automatically fix failing tests |
| difftests | AI test generator — write tests for your diffs |
| gpr | AI PR description + commit message generator |
| gitbrief | Pack your codebase into LLM context |
| standup-ai | AI daily standup generator |
| changelog-ai | AI CHANGELOG generator |
| prcat | AI PR reviewer for incoming PRs |
| chronicle | Turn git history into stories |
License
Business Source License 1.1 — free for non-commercial use. See LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file testfix-0.1.0.tar.gz.
File metadata
- Download URL: testfix-0.1.0.tar.gz
- Upload date:
- Size: 15.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e3b9df3311b6095f48b56875ccaf0747fd7cf43ea265f94fc7ee66aa0d6e5bd
|
|
| MD5 |
c6601d711094b100444f770594e5f969
|
|
| BLAKE2b-256 |
603230d9d9c2cf7bfc7a4c64b0d70d32bc1bceec73f22cbcb5b0581120010b7f
|
File details
Details for the file testfix-0.1.0-py3-none-any.whl.
File metadata
- Download URL: testfix-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e370da58799043db05a2f64d544158104bf0bd84f4c5afa104e0b4678b4451bf
|
|
| MD5 |
ade633ed41df13a6f1acda03133a2986
|
|
| BLAKE2b-256 |
4c22bf74f879d4c5b817e3bc613571c4b41494ee00961b427aadbb9f376d5d42
|