用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/sawrus/agent-guides --skill test-data-management命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Production-grade GitHub Actions workflows — reusable workflows, OIDC cloud auth, caching, matrix builds, and environment protection rules. Use when the user creates, reviews, or debugs CI/CD pipelines in .github/workflows, or asks about GitHub Actions deployment, OIDC authentication, or workflow optimization.
Systematic diagnosis of Kubernetes pod failures — CrashLoopBackOff, OOMKilled, Pending, ImagePullBackOff, and service connectivity issues. Use when the user encounters pods not starting, container restart loops, scheduling failures, or service unreachability in a K8s cluster.
Implement distributed tracing with OpenTelemetry, Tempo/Jaeger — instrumentation, sampling, and trace-to-log correlation. Use when the user asks about distributed tracing, OpenTelemetry setup, span instrumentation, trace propagation, or connecting traces to logs and metrics.
基于 SOC 职业分类
正在显示 SKILL.md
| name | test-data-management |
| type | skill |
| description | Manage test data with factories, fixtures, isolation strategies, and cleanup to prevent test pollution. |
| related-rules | ["test-strategy.md","test-data.md"] |
| allowed-tools | Read, Write, Edit, Bash |
Expertise: Factory functions, database isolation, seed data strategies, test pollution prevention.
# tests/factories.py
from faker import Faker
from decimal import Decimal
import pytest_asyncio
fake = Faker()
def build_user(**overrides) -> dict:
"""Build a user dict — does NOT write to DB"""
return {
"email": fake.email(domain="example-test.com"), # Never real domains
"name": fake.name(),
"role": "viewer",
"password_hash": "hashed_test_password",
**overrides,
}
def build_order(**overrides) -> dict:
return {
"status": "pending",
"total_amount": Decimal("99.99"),
"currency": "USD",
**overrides,
}
# Async factory fixture — writes to DB
@pytest_asyncio.fixture
async def create_user(db_session):
created = []
async def _create(**overrides):
user = User(**build_user(**overrides))
db_session.add(user)
await db_session.flush() # Get ID without committing
created.append(user)
return user
yield _create
# Cleanup is handled by transaction rollback (see isolation below)
# Usage in test
async def test_user_can_view_own_profile(create_user, client):
user = await create_user(role="viewer")
response = await client.get(f"/users/{user.id}", headers=auth_headers(user))
assert response.status_code == 200
assert response.json()["email"] == user.email
# conftest.py
@pytest_asyncio.fixture
async def db_session(engine):
async with engine.connect() as conn:
transaction = await conn.begin()
session = AsyncSession(bind=conn)
yield session
await transaction.rollback() # Rollback after each test — zero pollution
await session.close()
@pytest_asyncio.fixture(autouse=True)
async def clean_tables(db_session):
yield
# After test: truncate in reverse FK order
await db_session.execute(text("TRUNCATE order_items, orders, users RESTART IDENTITY CASCADE"))
await db_session.commit()
# docker-compose.test.yml
services:
db-test:
image: postgres:16
environment:
POSTGRES_DB: myapp_test
tmpfs: [/var/lib/postgresql/data] # In-memory — fast and isolated per run
# tests/e2e/seeds/standard.py
async def seed_standard_dataset(db: AsyncSession):
"""
Creates a deterministic dataset for E2E tests.
All IDs and values are fixed — tests can reference them directly.
"""
# Admin user — for management UI tests
admin = User(id=1, email="admin@test.example", role="admin", ...)
# Regular user — for end-user flow tests
user = User(id=2, email="user@test.example", role="viewer", ...)
# Products — for order flow tests
product_a = Product(id=101, name="Widget A", price=Decimal("29.99"), stock=100)
product_b = Product(id=102, name="Widget B", price=Decimal("49.99"), stock=50)
db.add_all([admin, user, product_a, product_b])
await db.commit()
# Apply before E2E suite
@pytest.fixture(scope="session", autouse=True)
async def seed(db_session):
await seed_standard_dataset(db_session)
# ❌ Shared mutable state between tests
orders = [] # module-level list
def test_1():
orders.append(create_order()) # test 1 adds
def test_2():
assert len(orders) == 0 # fails if test_1 ran first — order-dependent
# ✅ Each test creates its own data
async def test_order_count_for_new_user(create_user, client):
user = await create_user()
response = await client.get(f"/users/{user.id}/orders")
assert response.json()["count"] == 0 # always true — isolated
# ❌ Real email addresses in test data — risk of sending to real people
user = build_user(email="john.doe@gmail.com")
# ✅ Always use test-safe domains
user = build_user(email=fake.email(domain="example-test.com"))
# Verify no test data leaked to production DB
SELECT count(*) FROM users WHERE email LIKE '%example-test.com%';
# → Should always be 0 in production
# Verify test DB is clean before test run
SELECT count(*) FROM users;
# → Should be 0 or match seed count only