Test data management with fixtures and factories. Use when creating test data strategies, implementing data factories, managing fixtures, or seeding test databases.
/plugin marketplace add yonatangross/skillforge-claude-plugin/plugin install skillforge-complete@skillforgeThis skill inherits all available tools. When active, it can use any tool Claude has access to.
checklists/test-data-checklist.mdreferences/factory-patterns.mdtemplates/factory-boy.pyCreate and manage test data effectively.
from factory import Factory, Faker, SubFactory, LazyAttribute
from app.models import User, Analysis
class UserFactory(Factory):
class Meta:
model = User
email = Faker('email')
name = Faker('name')
created_at = Faker('date_time_this_year')
class AnalysisFactory(Factory):
class Meta:
model = Analysis
url = Faker('url')
status = 'pending'
user = SubFactory(UserFactory)
@LazyAttribute
def title(self):
return f"Analysis of {self.url}"
# Usage
user = UserFactory()
analysis = AnalysisFactory(user=user, status='completed')
import { faker } from '@faker-js/faker';
interface User {
id: string;
email: string;
name: string;
}
const createUser = (overrides: Partial<User> = {}): User => ({
id: faker.string.uuid(),
email: faker.internet.email(),
name: faker.person.fullName(),
...overrides,
});
const createAnalysis = (overrides = {}) => ({
id: faker.string.uuid(),
url: faker.internet.url(),
status: 'pending',
userId: createUser().id,
...overrides,
});
// Usage
const user = createUser({ name: 'Test User' });
const analysis = createAnalysis({ userId: user.id, status: 'completed' });
// fixtures/users.json
{
"admin": {
"id": "user-001",
"email": "admin@example.com",
"role": "admin"
},
"basic": {
"id": "user-002",
"email": "user@example.com",
"role": "user"
}
}
import json
import pytest
@pytest.fixture
def users():
with open('fixtures/users.json') as f:
return json.load(f)
def test_admin_access(users):
admin = users['admin']
assert admin['role'] == 'admin'
# seeds/test_data.py
async def seed_test_database(db: AsyncSession):
"""Seed database with test data."""
# Create users
users = [
UserFactory.build(email=f"user{i}@test.com")
for i in range(10)
]
db.add_all(users)
# Create analyses for each user
for user in users:
analyses = [
AnalysisFactory.build(user_id=user.id)
for _ in range(5)
]
db.add_all(analyses)
await db.commit()
@pytest.fixture
async def seeded_db(db_session):
await seed_test_database(db_session)
yield db_session
@pytest.fixture
def user():
return UserFactory()
@pytest.fixture
def user_with_analyses(user):
analyses = [AnalysisFactory(user=user) for _ in range(3)]
return {"user": user, "analyses": analyses}
@pytest.fixture
def completed_workflow(user_with_analyses):
for analysis in user_with_analyses["analyses"]:
analysis.status = "completed"
return user_with_analyses
@pytest.fixture(autouse=True)
async def clean_database(db_session):
"""Reset database between tests."""
yield
# Clean up after test
await db_session.execute("TRUNCATE users, analyses CASCADE")
await db_session.commit()
| Decision | Recommendation |
|---|---|
| Strategy | Factories over fixtures |
| Faker | Use for realistic random data |
| Scope | Function-scoped for isolation |
| Cleanup | Always reset between tests |
unit-testing - Test patternsintegration-testing - Database testsdatabase-schema-designer - Schema designKeywords: fixture, test fixture, pytest fixture, conftest Solves:
Keywords: factory, FactoryBoy, test factory, model factory Solves:
Keywords: seed, seed data, database seed, initial data Solves:
Keywords: cleanup, teardown, reset, isolation Solves:
Keywords: anonymize, faker, synthetic data, mock data Solves:
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.