Skip to main content

AI-powered CLI to automatically fix failing tests — non-interactive, pipeable, CI-ready

Project description

testfix

PyPI version Python

AI-powered CLI that automatically fixes failing tests — non-interactive, pipeable, CI-ready.

# Tests failing? Just run testfix.
$ testfix pytest

──────────────────────── Attempt 1/5 ────────────────────────
🔴 2 failing, 8 passing (attempt 1)
   └─ test_login  tests/test_auth.py:10
   └─ test_register  tests/test_auth.py:25

🤖 Asking claude to fix 2 failure(s)…
Generated 1 file fix(es)

─── src/auth.py ──────────────────────────────────────────────
--- a/src/auth.py
+++ b/src/auth.py
@@ -3,7 +3,7 @@
 def login(user, password):
-    return db.find(user) is not None        # BUG: doesn't check password
+    return db.find(user, password) is not None

   Applied fix to auth.py (backup: .testfix.bak)

──────────────────────── Attempt 2/5 ────────────────────────
✅ All tests pass! (attempt 2)

Why testfix?

Every developer faces the same loop: run tests → fix code → run tests → ...

Tools like aider are powerful but require an interactive session. testfix is different:

Feature testfix aider
Non-interactive ❌ (interactive REPL)
CI/CD ready
Pre-push hook
Pipe-friendly
Local LLM (ollama)
Auto-retry loop manual

Install

pip install testfix

Requires Python 3.9+ and one of: Anthropic API key, OpenAI API key, or ollama running locally.

Usage

# Basic: run pytest, fix failures, retry up to 5 times
testfix pytest

# Specific test file
testfix pytest tests/test_auth.py

# Max iterations
testfix --max-tries 3 pytest

# Fix once and re-run (equivalent to --max-tries 2)
testfix --once pytest

# Preview fixes as diffs WITHOUT applying
testfix --dry-run pytest

# Use OpenAI instead of Claude
testfix --provider openai pytest

# Use local ollama (free, no API key needed)
testfix --provider ollama pytest

# Use a stronger model for hard bugs
testfix --provider openai --model gpt-4o pytest

# Focus fixes on a specific source file
testfix --file src/auth.py pytest

# Works with any test runner
testfix npm test
testfix go test ./...
testfix cargo test
testfix vitest

Supported Test Frameworks

Framework Failure parsing Exit code
pytest ✅ Full traceback
jest / vitest ✅ Test name + location
go test ✅ Test name + file:line
cargo test ✅ Test name
rspec ✅ Test name + location

Pre-push hook

Automatically fix failing tests before every push:

# .git/hooks/pre-push
#!/bin/sh
testfix --once --provider ollama pytest

LLM Providers

# Claude (default) — best quality
export ANTHROPIC_API_KEY=sk-ant-...
testfix pytest

# OpenAI
export OPENAI_API_KEY=sk-...
testfix --provider openai pytest

# Local ollama (free, private, no API key)
# Install: https://ollama.ai then: ollama pull qwen2.5:7b
testfix --provider ollama pytest

How it works

  1. Run your test command and capture output
  2. Parse failures: test names, file paths, tracebacks
  3. Find the source files that need fixing (not the test files)
  4. Ask AI to fix the source code based on the failure context
  5. Apply patches (with .testfix.bak backups)
  6. Repeat until all tests pass or max tries reached

CI usage

# GitHub Actions
- name: Fix and test
  run: |
    pip install testfix
    testfix --provider openai --max-tries 3 pytest
  env:
    OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

Full developer workflow

Combine with the rest of the ecosystem for end-to-end AI-assisted development:

# 1. Morning standup
standup-ai --yesterday

# 2. Review your code before committing
critiq --staged

# 3. Fix failing tests automatically
testfix pytest

# 4. Generate commit message
gpr --commit

# 5. Generate PR description
gpr

# 6. Pack context for AI code review
gitbrief --changed-only

# 7. Generate changelog on release
changelog-ai --since v1.0.0

Install the full suite:

pip install standup-ai critiq testfix gpr gitbrief changelog-ai

Related tools

  • critiq — AI code reviewer (catches issues before they become failing tests)
  • difftests — AI test generator (generates tests for your diffs)
  • gpr — AI PR description generator
  • gitbrief — AI context packer for LLMs
  • standup-ai — AI daily standup generator
  • changelog-ai — AI changelog generator
  • prcat — AI PR reviewer for teammate PRs

License

Business Source License 1.1 — free for individuals and non-commercial use. Commercial use requires a license after the Change Date (2028-01-01), at which point this project converts to Apache 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

testfix_ai-0.2.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

testfix_ai-0.2.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file testfix_ai-0.2.0.tar.gz.

File metadata

  • Download URL: testfix_ai-0.2.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for testfix_ai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3c54559bd8e1caabea4fa7056c4bdd84427fe7a090c971f02b623337672157dc
MD5 469e9818efd075379c6858037a1d475c
BLAKE2b-256 f5d3d00a45f456c733032eed558cdc2b93b57f5e287f760659175fc324e98cae

See more details on using hashes here.

File details

Details for the file testfix_ai-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: testfix_ai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for testfix_ai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac416ace80c36344ac8622469718dce1b299cb6c7c521bc12f1e08dd841af727
MD5 492a1a1a14348b53663af9d1fa9eaefc
BLAKE2b-256 26a71ba0dd9fe8de6f2482749623063112e483bedf7e61cc6ded581d4cb3ef01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page