pytest
Skill1 starsChanged 36 days agoMITView on GitHub
Use when writing or fixing Python tests with pytest — fixtures and scopes, conftest.py, parametrize, tmp_path/monkeypatch, marks, async tests, pytest-cov.
8 other projects use a version of this.
Adopted by
Most recently taken up by
- amutaal122/ai-engineer-mastertheir own version, first seen Nov 29, 2026
- marcioaltoe/skillstheir own version, first seen Nov 29, 2026
- Taimoor-Kamran/claude-code-skillstheir own version, first seen Nov 22, 2026
- nealepetrillo/claude-skills-pytesttheir own version, first seen Nov 22, 2026
- G1Joshi/Agent-Skillstheir own version, first seen Oct 13, 2026
- prowler-cloud/prowlertheir own version, first seen Oct 8, 2026
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- prowler-cloud/prowler★ 15ksame name
- microsoft/debugpy★ 2.5ksame name
- G1Joshi/Agent-Skills★ 15same name
- imankulov/skills★ 4same name
- nealepetrillo/claude-skills-pytest★ 1same name
- Taimoor-Kamran/claude-code-skills★ 1same name
- amutaal122/ai-engineer-master★ 0same name
- marcioaltoe/skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository41 other files it gives its agents.
- AGENTS.mdAGENTS.md
- patient/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- patient/CLAUDE.mdCLAUDE.md
- author-skillSkill
- context-intakeSkill
- debug-failureSkill
- dominioSkill
- follow-up-prsSkill
- locate-codeSkill
- master-planSkill
- plan-advancedSkill
- plan-simpleSkill
- quality-attributesSkill
- resolve-ticketSkill
- review-diffSkill
- scoped-gateSkill
- secure-by-designSkill
- security-invariantsSkill
- solution-designSkill
- spec-bootstrapSkill
- verify-before-doneSkill
- author-skillSkill
- context-intakeSkill
- debug-failureSkill
- dominioSkill
- follow-up-prsSkill
- locate-codeSkill
- master-planSkill
- plan-advancedSkill
- plan-simpleSkill
- pytestSkill
- quality-attributesSkill
- resolve-ticketSkill
- review-diffSkill
- scoped-gateSkill
- secure-by-designSkill
- security-invariantsSkill
- solution-designSkill
- spec-bootstrapSkill
- verify-before-doneSkill
The file
We split this skill into the rules it gives an agent
6 rules. 0 are common, 0 are distinctive, and 6 are very specific to this project.
0
Common
Most of the 7 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
When authoring or debugging pytest tests: sharing setup with fixtures, table-driving cases, isolating files and environment, testing async …
- Very specific: line 41
Fixture scope defaults to
function: Use scope="module" or "session" only for costly, read-only setup. - Very specific: line 43
Isolate the filesystem and environment: Use tmp_path for files and monkeypatch.setenv / monkeypatch.setattr for env and attributes.
- Very specific: line 51
Put setup in fixtures, not module-level state.
- Very specific: line 53
Use tmp_path and monkeypatch.
- Very specific: line 73
No real network, clock, or filesystem writes outside tmp_path.
“Common” is measured: kept by at least 6 in 10 of the 7 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- navori:managed id="pytest" hash="c8cb8961" version="0.11.1" source="@navori/core" fmkeys="name,description,metadata" -->pytest — conventions
When to use this skill
When authoring or debugging pytest tests: sharing setup with fixtures, table-driving cases, isolating files and environment, testing async code, or measuring coverage. Plain assert is the assertion API; pytest rewrites it to show values on failure.
The pattern
Arrange–act–assert, one behavior per test, setup in fixtures, cases in parametrize.
import pytest
@pytest.fixture
def cart():
return Cart()
@pytest.mark.parametrize(
("qty", "total"),
[(1, 10), (3, 30), pytest.param(0, 0, id="empty")],
)
def test_total(cart, qty, total):
cart.add(price=10, qty=qty)
assert cart.total() == total
def test_rejects_negative(cart):
with pytest.raises(ValueError, match="qty"):
cart.add(price=10, qty=-1)Gotchas that bite
- Fixture scope defaults to
function. Usescope="module"or"session"only for costly, read-only setup; shared mutable state couples tests. - Shared fixtures go in
conftest.py. pytest discovers it automatically, with no import; keep it per directory, scoped to the tests beneath it. - Isolate the filesystem and environment. Use
tmp_pathfor files andmonkeypatch.setenv/monkeypatch.setattrfor env and attributes; pytest undoes them after each test. - Async tests need a plugin.
pytest-asyncioneeds@pytest.mark.asyncio(orasyncio_mode = "auto"in config);anyioneeds@pytest.mark.anyio. Without one, the coroutine is never awaited: the test is skipped with a warning (a failure in pytest 8.4+). - No network in unit tests. Fake the client with
monkeypatchor a fixture; reserve real I/O for a marked integration suite. - Register custom marks. Declare them under
markersinpyproject.toml, or--strict-markersfails on typos.
Hard rules
- Name files
test_*.pyand functionstest_*. - Put setup in fixtures, not module-level state; use
yieldfixtures for teardown. - Table-drive similar cases with
parametrizeand readableids. - Use
tmp_pathandmonkeypatch; never write to the repo or leave env changed. - Pick one async marker style for the repo and configure it once.
- Coverage via
pytest-cov:pytest --cov=<package> --cov-report=term-missing. Assert behavior, not a line target.
Quick table
| Need | Use |
| Shared setup | @pytest.fixture in conftest.py |
| Many inputs | @pytest.mark.parametrize |
| Temp files | tmp_path |
| Patch env/attr | monkeypatch.setenv / setattr |
| Expected error | pytest.raises(Err, match=...) |
| Skip / expected fail | @pytest.mark.skip / xfail |
| Run a subset | pytest -k name / -m mark |
Before declaring done
- Each test fails for the right reason; no order dependence between tests.
- Async tests carry the marker their plugin requires.
- No real network, clock, or filesystem writes outside
tmp_path. ruff check .green.
<!-- /navori:managed id="pytest" -->This repo's tests (your domain)
<!-- user: add here what only applies to THIS repo. Suggestions:
- Where tests live and the naming convention.
- What conftest.py provides (app, DB, client fixtures).
- What is mocked by convention (network, clock, storage) and what is never mocked.
- Coverage the repo requires and which areas are exempt.
-->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

