Expert guidance for writing high-quality pytest tests. Use when writing tests, setting up fixtures, parametrizing, mocking, or reviewing test code.
69
85%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
<essential_principles>
Test Independence
Naming Conventions
test_*.py or *_test.pytest_<description>()Test<ClassName>lowercase_with_underscoresDirectory Structure
tests/
├── conftest.py # Shared fixtures
├── unit/
│ └── test_module.py
├── integration/
│ └── test_api.py
└── fixtures/ # Test data filesCore Testing Rules
assert statements (pytest provides detailed failure messages)</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:
| Task | Reference |
|---|---|
| Setting up fixtures, scopes, factories | references/fixtures.md |
| Parametrizing tests, multiple inputs | references/parametrization.md |
| Mocking, patching, faking dependencies | references/mocking.md |
| Markers, exceptions, assertions, async | references/patterns.md |
298fce7
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.