pytest-patterns
Skill2 starsChanged 22 days agoMITView on GitHub
Write, review and diagnose Python pytest cases, handling fixture lifecycle, parametrization, mocks, async and parallel isolation. Use for a defined testing task; do not convert every Python script to pytest, and do not install plugins automatically.
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 6 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Write the contract under test as independent expectations first, then choose fixtures, parametrization and stubs.
- Very specific: line 25
Write input, action, output/error/side effect, and parametrize with explicit expectations and readable IDs.
- Distinctive: line 27
Follow Fixtures and async to decide scope, resource acquisition/release, patch boundary, async mode and cancellation.
- Distinctive: line 28
Use existing fixtures where possible.
- Very specific: line 31
Run the affected cases first and confirm the actually collected set, that the test bodies executed and the final state of cleanup.
- Distinctive: line 33
Use pytest evidence to deliver scope, versions, plugins, original failures and re-verification.
- Distinctive: line 39
Keep both assertion failures and cleanup failures.
- Distinctive: line 43
When resources are insufficient, change concurrency first.
- Very specific: line 53
Follow the local resource cleanup rule of task-implementation: register identity on creation, reclaim only objects registered this run at …
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
pytest testing method
Write the contract under test as independent expectations first, then choose fixtures, parametrization and stubs; test count and coverage are no substitute for behavioural correctness.
Inputs and capability
Take the target module/behaviour, allowed files and external boundaries, the actual Python/pytest/plugin versions, the existing test entry, async mode, fixture ownership, node resources and how results are counted. Without pytest, cases can be written and separable standard-library logic executed, but this cannot be called a pytest pass; without pytest-mock use unittest.mock/monkeypatch, without xdist run serially, and install neither automatically.
Without an async plugin, do not treat a bare async def as executed: being collected or skipped does not prove the function body ran. With no plugin and a test that fully owns its event loop, asyncio.run may be used inside an ordinary test; with loop-bound fixtures or an existing async framework, settle the compatible mode first and do not start a nested event loop.
Method routing
- Write input, action, output/error/side effect, and parametrize with explicit expectations and readable IDs. A counterexample must be able to expose the target defect; do not fix assertions to fit a wrong implementation.
- Follow Fixtures and async to decide scope, resource acquisition/release, patch boundary, async mode and cancellation. Use existing fixtures where possible; do not build a large autouse fixture for uniformity.
- For external integration or parallel runs, follow Parallelism and integration for independent data, worker/attempt identity and cleanup; external calls run only in a permitted isolated environment.
- Run the affected cases first and confirm the actually collected set, that the test bodies executed and the final state of cleanup; run related regressions afterwards when needed. Record failed/error/skip/xfail/xpass/not run; exit code 0 cannot stand in for all expectations passing.
- Use pytest evidence to deliver scope, versions, plugins, original failures and re-verification; do not rerun unrelated tests or push TDD/coverage thresholds without need.
Failure and continuation
Tell apart collection, fixture setup, test call and teardown. A setup failure may not have reached yield yet; resources already acquired successfully must be released. Keep both assertion failures and cleanup failures; a teardown failure must not overwrite the first business error. An unavailable dependency blocks only the corresponding integration; pure-logic checks may continue.
On continuation, verify the candidate, selected set, execution handles, exclusive resources and completed results; do not assume the old process has stopped. When resources are insufficient, change concurrency first; do not skip required cases.
Resource suggestion: mechanical execution uses low/low; routine fixtures/parametrization use normal/medium; event loop, shared state and concurrency failures use normal/high.
Grade words map to actual execution configuration through the project resource mapping.
Normal example: tmp_path per case, the real function under test, a stub at the HTTP boundary; without xdist, run the same set serially. Counterexample: the whole suite sharing a fixed temp.txt, counting a skipped async test as passed, rerunning until green and then deleting the first-run failure.
Wrap-up cleanup: processes, containers, temporary files and test data started outside fixtures are reclaimed after the session ends;
built-in temporary directories such as tmp_path follow pytest's own retention policy, and the global basetemp is not cleaned by hand.
Follow the local resource cleanup rule of task-implementation: register identity on creation, reclaim only objects registered this run at wrap-up,
write evidence to be kept and cleanup failures into the receipt, and use no global cleanup commands.
Sources
- Pinned source: EC08 python-testing.
- Adopted the fixture/yield, parametrization, mock/autospec, async and temporary-resource topics; cleanup on setup failure, the strict/auto distinction, worker isolation and the no-plugin path are own-authored for this package. Dropped mandatory TDD for every task, fixed coverage, shared temporary files, automatic plugin installation and undeclared external calls.
- License: shipped with the package as LICENSE-EC.txt (EC, MIT); library-wide third-party summary in the root THIRD_PARTY_NOTICES.md. Copy the license file along when copying this package alone.
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- cohen-liel/hivemind★ 108same name
- hieutrtr/ai1-skills★ 8same 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 repository39 other files it gives its agents.
- ai-trace-auditSkill
- ai-workspace-governanceSkill
- archive-maintenanceSkill
- change-reviewSkill
- cloud-api-integrationSkill
- coding-conventionsSkill
- container-image-managementSkill
- context-handoffSkill
- deployment-patternsSkill
- docker-local-environmentSkill
- documentation-authoringSkill
- estimationSkill
- external-dependency-simulationSkill
- gitlab-webhook-local-gitSkill
- go-patternsSkill
- go-testingSkill
- grpc-proto-contractSkill
- guided-evidence-collectionSkill
- http-api-designSkill
- jenkins-pipeline-jjbSkill
- ldap-rbacSkill
- mysql-migration-safetySkill
- plan-designSkill
- plan-reviewSkill
- playwright-e2eSkill
- project-contextSkill
- readonly-ops-diagnosticsSkill
- redis-patternsSkill
- release-readinessSkill
- role-bootstrapSkill
- security-reviewSkill
- skill-maintenanceSkill
- subtask-dispatchSkill
- systematic-diagnosisSkill
- task-implementationSkill
- test-strategySkill
- verification-gateSkill
- vue3-developmentSkill
- vue-testingSkill
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.

