Test and Fix Loop
Purpose
An autonomous loop for the agent to identify, analyze, and fix failing unit tests using pytest.
Loop Logic
- •Identify: Run
make testto identify failing tests. - •Analyze: Examine the
pytestoutput to determine:- •The failing test file and line number.
- •The expected vs actual values (assertion errors).
- •Tracebacks for runtime errors.
- •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).
- •Verify: Re-run
make test(oruv run pytest path/to/failing_test.pyfor 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
- •
make testfails intests/test_math.pybecauseadd(2, 2)returned5. - •Agent analyzes
src/your_package/math.pyand finds a typoa + b + 1. - •Agent fixes the typo to
a + b. - •
make testpasses.
Resources
- •Python Development Commands: Common commands for testing and managing dependencies.
- •Pytest Documentation: Official documentation for the pytest framework.
- •Unit Test Manners: Project-specific testing guidelines.