一键导入
test-gen
Generate comprehensive pytest integration tests for MCP tools and FastAPI endpoints. Includes fixtures, edge cases, and validation tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Generate comprehensive pytest integration tests for MCP tools and FastAPI endpoints. Includes fixtures, edge cases, and validation tests.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Generate production-ready FastAPI CRUD endpoints with SQLModel. Creates complete Create, Read, Update, Delete operations following project patterns.
Scaffold FastMCP tool implementations with database integration, error handling, and test session support. Generates production-ready MCP tools.
Manage Todo operations (Create, Read, Update, Delete) using SQLModel and Postgres. Use when the user wants to organize tasks.
基于 SOC 职业分类
| name | test-gen |
| description | Generate comprehensive pytest integration tests for MCP tools and FastAPI endpoints. Includes fixtures, edge cases, and validation tests. |
Auto-generate integration tests following project's pytest patterns with proper fixtures, database sessions, and >80% coverage for business logic.
/websites/sqlmodel_tiangolo for testing patternsconftest.py fixtures (session, sample_todo, sample_todos)import pytest
from sqlmodel import select
from src.mcp_server.models import Todo, TodoStatus
from src.mcp_server.tools.operation_name import operation_name
def test_operation_success(session):
"""Test successful operation with valid input."""
result = operation_name(
param="value",
_test_session=session
)
import json
data = json.loads(result)
assert data["success"] is True
assert "data" in data
# Verify database persistence
statement = select(Todo).where(Todo.id == data["data"]["id"])
todo = session.exec(statement).first()
assert todo is not None
assert todo.title == "Expected Value"
def test_operation_not_found(session):
"""Test operation with non-existent resource."""
result = operation_name(
param="nonexistent",
_test_session=session
)
import json
data = json.loads(result)
assert data["success"] is False
assert "error" in data
def test_operation_validation_error(session):
"""Test operation with invalid input."""
result = operation_name(
param="", # Invalid empty string
_test_session=session
)
import json
data = json.loads(result)
assert data["success"] is False
def test_operation_with_optional_params(session):
"""Test operation with all optional parameters."""
result = operation_name(
required_param="value",
optional_param="extra",
_test_session=session
)
import json
data = json.loads(result)
assert data["success"] is True
from fastapi.testclient import TestClient
from src.main import app
client = TestClient(app)
def test_create_endpoint(session):
"""Test POST endpoint with valid data."""
response = client.post(
"/todos/",
json={"title": "Test Todo", "description": "Test"}
)
assert response.status_code == 200
data = response.json()
assert data["title"] == "Test Todo"
assert data["id"] is not None
# Verify database
from src.mcp_server.models import Todo
from sqlmodel import select
todo = session.exec(select(Todo).where(Todo.id == data["id"])).first()
assert todo is not None
def test_create_endpoint_validation_error(session):
"""Test POST endpoint with missing required field."""
response = client.post("/todos/", json={"description": "No title"})
assert response.status_code == 422 # Validation error
def test_get_endpoint_not_found(session):
"""Test GET endpoint with non-existent ID."""
response = client.get("/todos/99999")
assert response.status_code == 404
assert "not found" in response.json()["detail"].lower()
User: "Generate tests for update_todo tool" Action: Read update_todo.py → Query Context7 → Generate test_update_todo.py with 5-7 test cases → Verify fixture usage