# Pytest Generate

> Generate comprehensive pytest test suites with fixtures, mocks, and coverage targets Use when this capability is needed.

- Skill: `tomevault-io/pytest-generate` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/pytest-generate`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/pytest-generate/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/pytest-generate

---


## Test Generation Protocol

**Framework:** pytest 8+, pytest-asyncio, pytest-cov, httpx (for FastAPI), factory-boy

**For each function/endpoint under test, generate:**
1. Happy-path test (valid input → expected output)
2. Edge case tests (boundary values, empty inputs, max limits)
3. Error path tests (invalid input → correct HTTP code / exception)
4. Auth tests (unauthenticated → 401, unauthorized → 403)
5. Integration test if DB or external service is involved

## Test Structure
```python
class TestResourceCreate:
    async def test_creates_resource_with_valid_payload(self, client, auth_headers, db):
        ...
    async def test_returns_422_on_missing_required_field(self, client, auth_headers):
        ...
    async def test_returns_401_without_auth(self, client):
        ...
    async def test_returns_403_for_insufficient_role(self, client, limited_auth_headers):
        ...
```

**Fixture rules:**
- Database fixtures: use transactions + rollback (never commit to test DB)
- External APIs: always mock with `respx` or `pytest-mock`
- Auth: provide `auth_headers` fixture at conftest level

## Output Expectations
- Minimum coverage target: 85% for new code, 100% for security-critical paths
- All async endpoints tested with `pytest-asyncio` and `anyio`
- Factory classes for all models in `tests/factories/`

## Quality Criteria
- Tests run in isolation (no shared state between test functions)
- No `time.sleep()` — use `freezegun` for time-dependent logic
- Test names are self-documenting (no comments needed to understand intent)

---
> Source: [azar-management-consulting/occp-core](https://github.com/azar-management-consulting/occp-core) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-06-16 -->

