AI-Powered Test Generation for Python/pytest
PraisonAI TestGen is an open-source, AI-powered test generation and maintenance platform. It autonomously generates, validates, and maintains unit tests as your codebase evolves.
pip install praisonai-testgen
from praisonai_testgen import TestGen
# Generate tests for a file
testgen = TestGen()
result = testgen.generate("src/calculator.py")
# Generate tests for a specific function
result = testgen.generate("src/calculator.py::add")
# Initialize TestGen in your project
testgen init
# Generate tests
testgen generate src/
testgen generate src/calculator.py
# Update tests for changed code
testgen update
# View coverage report
testgen report
TestGen is built on a DRY (Don’t Repeat Yourself) architecture:
┌─────────────────────────────────────────────────────────────────────────────┐
│ praisonai-testgen (this package) │
│ Test Generation • Maintenance • IDE/CI Integration │
└───────────────────────────────────┬─────────────────────────────────────────┘
│
┌───────────────────────┴───────────────────────┐
│ │
▼ ▼
┌───────────────────────┐ ┌───────────────────────┐
│ praisonaiagents │ │ testagent │
│ Agent orchestration │ │ Test validation │
│ Tool framework │ │ LLM-as-judge │
└───────────────────────┘ └───────────────────────┘
TestGen uses minimal agent definitions for clarity:
from praisonaiagents import Agent, tool
@tool
def parse_python_ast(file_path: str) -> dict:
"""Parse Python file and extract testable functions."""
import ast
with open(file_path) as f:
tree = ast.parse(f.read())
# ... extract functions
return {"functions": [...]}
analyzer = Agent(
name="Analyzer",
instructions="Parse Python code and identify testable functions",
tools=[parse_python_ast],
)
MIT License - see LICENSE for details.