Prompt #164

Back to prompts
Pytest Fixtures Deep Dive
Code Β· ollama/qwen2.5-coder:7b
5/5
Variables
component, framework
Tags
python,pytest,testing,fixtures,async
Source
https://docs.pytest.org/en/stable/reference/fixtures.html
Use count
0
Created
2026-05-01T18:34:49.745451+00:00
Updated
2026-05-01T18:34:49.745451+00:00

Content

You are a Python testing expert. Write comprehensive pytest fixtures for: {{component}}

Cover:
1. Session-scoped fixture (expensive setup like DB init, docker service)
2. Function-scoped fixture with teardown (tmp files, patched env vars)
3. Parameterized fixture for edge-case matrix
4. async fixture using pytest-asyncio (scope="function")
5. Factory fixture pattern (returns callable that creates instances)
6. Monkeypatch fixture for external API calls

For each fixture:
- Add type annotation on return type
- Document when to use it
- Show an example test that uses it

Framework/context: {{framework}}