praisonai-testgen

PraisonAI TestGen

AI-Powered Test Generation for Python/pytest

Python 3.11+ License: MIT

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.

Features

Installation

pip install praisonai-testgen

Quick Start

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")

CLI Usage

# 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

Architecture

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         │
    └───────────────────────┘                   └───────────────────────┘

Mini Agent Pattern

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],
)

Documentation

License

MIT License - see LICENSE for details.