Expert guidance for writing high-quality pytest tests. Use when writing tests, setting up fixtures, parametrizing, mocking, or reviewing test code.
Installation
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Use plain assert statements (pytest provides detailed failure messages)
One logical assertion per test when practical
Test edge cases: empty inputs, boundaries, invalid data, errors
Keep tests focused and readable
</essential_principles>
<quick_reference>
Pattern
Use Case
@pytest.fixture
Setup/teardown, dependency injection
@pytest.mark.parametrize
Run test with multiple inputs
@pytest.mark.skip
Skip test temporarily
@pytest.mark.xfail
Expected failure (known bug)
pytest.raises(Exception)
Test exception raising
pytest.approx(value)
Float comparison
mocker.patch()
Mock dependencies
conftest.py
Share fixtures across modules
Common Commands
pytest -v # Verbose
pytest -x # Stop on first failure
pytest --lf # Run last failed
pytest -k "pattern"# Match test names
pytest -m "marker"# Run marked tests
pytest --cov=src # Coverage report
</quick_reference>
Based on what you're doing, read the relevant reference: