# Test And Fix

> Run unit tests and automatically fix code failures, regression bugs, or test mismatches. Use when tests are failing, after implementing new features, or to repair "broken" tests. Use when this capability is needed.

- Skill: `tomevault-io/test-and-fix` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/test-and-fix`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/test-and-fix/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/test-and-fix

---


# Test and Fix Loop

## Purpose

An autonomous loop for the agent to identify, analyze, and fix failing unit tests using `pytest`.

## Loop Logic

1. **Identify**: Run `make test` to identify failing tests.
2. **Analyze**: Examine the `pytest` output to determine:
   - The failing test file and line number.
   - The expected vs actual values (assertion errors).
   - Tracebacks for runtime errors.
3. **Fix**: Apply the minimum necessary change to either the source code (if it's a bug) or the test code (if the test is outdated).
4. **Verify**: Re-run `make test` (or `uv run pytest path/to/failing_test.py` for speed).
   - If passed: Move to the next failing test or finish if all are resolved.
   - If failed: Analyze the new failure and repeat the loop.

## Termination Criteria

- All tests pass (as reported by `make test`).
- Reached max iteration limit (default: 5).
- The error persists after multiple distinct fix attempts, indicating a need for human intervention.

## Examples

### Scenario: Fixing a logic error

1. `make test` fails in `tests/test_math.py` because `add(2, 2)` returned `5`.
2. Agent analyzes `src/your_package/math.py` and finds a typo `a + b + 1`.
3. Agent fixes the typo to `a + b`.
4. `make test` passes.

## Resources

- [Python Development Commands](../common-references/python-commands.md): Common commands for testing and managing dependencies.
- [Pytest Documentation](https://docs.pytest.org/): Official documentation for the pytest framework.
- [Unit Test Manners](../../../.cursor/rules/tech-stack.mdc): Project-specific testing guidelines.

---
> Converted and distributed by [TomeVault](https://tomevault.io/claim/yu-iskw) — claim your Tome and manage your conversions.
<!-- tomevault:4.0:skill_md:2026-04-16 -->

