agentsclimarketplace

Pytest mastery

Skill Amey-Thakur/AI-SKILLS/skills/python/pytest-mastery

Plug-and-play skills and prompts for every AI coding agent

Install
npx -y skills add Amey-Thakur/AI-SKILLS --skill pytest-mastery

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • 19 days oldThe repository was created 19 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
  • 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Structure pytest suites with fixtures, parametrize, and markers so tests stay fast, isolated, and readable. Use when writing Python tests or untangling a slow, fixture-heavy suite.

SKILL.md

2.3 KB, as published. Nobody here has run it

Pytest mastery

Fixtures are dependency injection for tests: each test states what it needs, pytest builds it, and scope controls how much is shared.

Method

  1. Scope fixtures by cost, not convenience. Default function scope for anything mutable; session scope only for expensive immutable resources (a container, a compiled artifact). A session-scoped mutable fixture is the classic source of order-dependent flakiness.
  2. Layer conftest.py by directory. Repo-root conftest holds universal fixtures; each package's tests get their own conftest for local ones. Never import fixtures across test files; discovery through conftest is the mechanism.
  3. Parametrize instead of copy-pasting. @pytest.mark.parametrize("raw,expected", CASES, ids=str) turns a table of cases into individual test items with readable names. Stack two parametrize decorators to get the cross product.
  4. Use markers as a vocabulary, registered in pyproject. slow, integration, requires_gpu; select with -m "not slow" locally and run everything in CI. Unregistered markers are typos waiting to pass silently; set --strict-markers.
  5. Prefer tmp_path, monkeypatch, and capsys over hand-rolled setup. tmp_path gives an isolated directory per test; monkeypatch.setenv and .setattr undo themselves; capsys asserts on output without redirecting streams manually.
  6. Assert one behavior per test, plainly. Bare assert with pytest's rewriting gives rich diffs; pytest.raises(ValueError, match="port") pins the error and its message. If a test needs a comment to explain what it checks, its name is wrong.
  7. Keep the suite fast enough to run on every save. Measure with --durations=10; push anything over a second behind a slow marker. pytest -x --ff (fail fast, failed first) is the debugging loop.

Boundaries

  • Do not mock what you own; restructure so the seam is a real interface. Mock only true externals (network, clock, randomness).
  • Fixture chains deeper than three levels hide the arrange step; inline the setup or build an explicit builder function.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.