Loading...
Loading...
Create comprehensive unit tests, integration tests, and end-to-end tests using pytest for Python projects. Specializes in FastAPI testing with TestClient, async testing with pytest-asyncio, SQLModel/SQLAlchemy database testing, fixture generation, and test configuration setup. Use when you need test coverage, want to implement TDD/BDD, create test suites for functions or API endpoints, add edge case testing, or improve code quality with automated testing. Triggers include requests like "write tests for this module", "create pytest fixtures", "test this FastAPI endpoint", "setup pytest configuration", or "generate test file".
npx skill4agent add ameen-alam/ai-400-class pytest-builderpython3 scripts/generate_test.py myapp/users.py --type unitpython3 scripts/setup_pytest_config.py . --template fastapipython3 scripts/generate_fixtures.py --fixtures database api_client --output tests/conftest.py# Basic unit tests
python3 scripts/generate_test.py myapp/module.py
# FastAPI integration tests
python3 scripts/generate_test.py myapp/routers/users.py --type integration
# Async tests
python3 scripts/generate_test.py myapp/async_service.py --async# Basic Python project
python3 scripts/setup_pytest_config.py . --template basic
# FastAPI project
python3 scripts/setup_pytest_config.py . --template fastapi
# Async project
python3 scripts/setup_pytest_config.py . --template asyncpytest.initests/tests/conftest.py# List available fixtures
python3 scripts/generate_fixtures.py --list
# Generate specific fixtures
python3 scripts/generate_fixtures.py --fixtures database api_client auth_token
# Generate all fixtures
python3 scripts/generate_fixtures.py --fixtures all
# Append to existing conftest.py
python3 scripts/generate_fixtures.py --fixtures mock_external_api --appenddatabaseasync_databaseapi_clientasync_clientmock_external_apitemp_filessample_userauth_tokenfrom fastapi.testclient import TestClient
from myapp.main import app
client = TestClient(app)
def test_read_items():
response = client.get("/items/")
assert response.status_code == 200
assert isinstance(response.json(), list)import pytest
from httpx import AsyncClient
@pytest.mark.asyncio
async def test_async_endpoint():
async with AsyncClient(app=app, base_url="http://test") as ac:
response = await ac.get("/items/")
assert response.status_code == 200import pytest
from sqlmodel import Session, create_engine, SQLModel
from sqlmodel.pool import StaticPool
@pytest.fixture(name="session")
def session_fixture():
engine = create_engine(
"sqlite:///:memory:",
connect_args={"check_same_thread": False},
poolclass=StaticPool,
)
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
yield sessionpython3 scripts/setup_pytest_config.py . --template fastapipython3 scripts/generate_fixtures.py --fixtures database api_client sample_userpython3 scripts/generate_test.py myapp/routers/items.py --type integrationpytestpython3 scripts/generate_test.py myapp/services/auth.py --output tests/unit/test_auth.pypython3 scripts/generate_fixtures.py --fixtures auth_token --appendpython3 scripts/generate_fixtures.py --fixtures async_database async_clientpytest --asyncio-mode=autotest_<feature>_<scenario>_<expected_outcome>tests/unit/tests/integration/assets/pytest.iniassets/conftest_basic.pyassets/conftest_fastapi.pyassets/test_template.py# Basic pytest
pip install pytest pytest-cov
# Async support
pip install pytest-asyncio
# FastAPI testing
pip install httpx
# Database testing
pip install sqlmodel