Skip to main content

AI-powered test failure analysis and fix suggestions

Project description

UnitSauce

AI-powered test failure analysis and auto-fix for Python projects.

UnitSauce analyzes failing tests, identifies bugs in your code changes, and generates fixes using Claude AI. Works as a CLI tool or GitHub Action.


Features

  • Automatic failure detection — Runs pytest and identifies failing tests
  • AI-powered analysis — Uses Claude to understand the bug from git diff
  • Smart fixes — Generates minimal code or test fixes
  • Verification — Confirms the fix actually works before reporting
  • PR comments — Posts fix suggestions directly to your pull request

Quick Start

CLI Usage

pip install unitsauce
# Auto-detect whether to fix code or test
unitsauce /path/to/project

# Force fix code only
unitsauce /path/to/project --mode code

# Force fix test only
unitsauce /path/to/project --mode test

# Output as markdown
unitsauce /path/to/project --output markdown

GitHub Action

Add to your workflow (.github/workflows/test.yml):

name: Tests
on:
  pull_request:

permissions:
  pull-requests: write

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 2
      
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - name: Install dependencies
        run: pip install pytest
      
      - name: Run tests
        run: pytest
      
      - name: UnitSauce Analysis
        if: failure()
        uses: zanstarasinic/unitsauce@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

Configuration

CLI Options

Option Description Default
--mode auto, code, or test auto
--output console, markdown, or json console

Environment Variables

Variable Required Description
ANTHROPIC_API_KEY Yes Your Anthropic API key
GITHUB_TOKEN For PR comments Provided automatically by GitHub Actions

Requirements

  • Python 3.10+
  • Git repository
  • Anthropic API key
  • pytest

How It Works

  1. Detects failures — Runs pytest and collects failing tests
  2. Analyzes changes — Gets git diff to see what changed
  3. Identifies affected code — Maps failures to modified functions
  4. Generates fix — Sends context to Claude, gets minimal fix
  5. Verifies — Applies fix, runs test again to confirm
  6. Reports — Shows diff or posts PR comment

Example PR Comment

UnitSauce Analysis

Found 1 failing test(s), fixed 1.

---

test_calculator.py::test_add

Error: assert 6 == 5

Fixed by: Updating test in test_calculator.py

- assert add(2, 3) == 5
+ assert add(2, 3) == 6

Local Development

git clone https://github.com/zanstarasinic/unitsauce.git
cd unitsauce
pip install -e .

License

MIT

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

unitsauce-0.1.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

unitsauce-0.1.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file unitsauce-0.1.1.tar.gz.

File metadata

  • Download URL: unitsauce-0.1.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for unitsauce-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c52fcb05e0732d48cb8ba211534abd476a98c1f84824601a461d467540315fe6
MD5 0eff3e38c5ff1930f1c174a739c9908c
BLAKE2b-256 bed26b4fb0b604d5000cd59509dc0ac6880cd06c0eaaba3f0bded386132e03d4

See more details on using hashes here.

File details

Details for the file unitsauce-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: unitsauce-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for unitsauce-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d9df949b923cc1018d8b7a2c343589d8764b5c1f7d812d7574d451cf7926aec8
MD5 063edc7869849272f6a4eb67d6eff59c
BLAKE2b-256 2b33a9387ff2555a06d70aa2f8eb207e22a05a4ac81816135c75308305b8a14d

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