1.7 KiB
1.7 KiB
Pytest Documentation Notes
!!! info "Primary sources" - Good integration practices - Fixture how-to - Marker examples - Configuration reference - Flaky tests
Agent Quick Path
Use this file when you need fast pytest scaffolding defaults without framework-specific details.
- Mirror source layout under
tests/. - Keep fixtures small and explicit; default to
functionscope. - Register markers up front in
pyproject.toml. - Validate structure first with
uv run pytest --collect-only -q. - Run fast lane with
uv run pytest -m unit -q.
Load other references only when needed:
- FastAPI routes/dependency injection/lifespan:
fastapi-testing.md - SQLAlchemy sessions/transactions/DB fixtures:
sqlalchemy-testing.md
Practical Guidance For This Skill
- Use src-aligned test layout and keep test discovery conventional.
- Keep fixtures small, composable, and explicit; use
yieldfor teardown. - Register custom markers and keep strict marker validation on.
- Separate quick unit runs from slower integration/external runs.
- Minimize flakiness by controlling shared state and avoiding hidden dependencies.
- Use
--collect-onlyand marker-filtered runs to validate scaffold quality early.
Commands Worth Remembering
uv run pytest --collect-only -quv run pytest -m unit -quv run pytest -m "not external" -quv run pytest -q