Skip to content
Skills Library
Programming · Testing

pytest-mastery

/pytest-mastery

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.

Repository
AI-SKILLS ↗
Licence
MIT
Last repository change
05.09.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 05.09.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

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.

Original author description

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.

How it works

  1. Method
  2. Boundaries
Original SKILL.md headings · 43 lines, 302 words
SKILL.md preview
---
name: pytest-mastery
description: 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.
---

# 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.

Versions

The database has no other skills named pytest-mastery.

Database snapshot: 13.11.2026 · package version 9c05a9eb6aeb (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100pytest-skill
    Generates production-grade pytest tests in Python with fixtures, parametrize, markers, mocking, and conftest patterns. Use when user mentions \"pytest\", \"conftest\", \"@pytest.fixture\", \"@pytest.mark\", \"Python test\".
  • 100pytest-skill
    Generates production-grade pytest tests in Python with fixtures, parametrize, markers, mocking, and conftest patterns. Use when user mentions \"pytest\", \"conftest\", \"@pytest.fixture\", \"@pytest.mark\", \"Python test\".
  • 100pytest
    pytest Python testing framework. Covers fixtures, parametrize, and mocking. Use for Python testing. USE WHEN: user mentions "pytest", "python test", "fixture", asks about "@pytest.fixture", "@pytest.mark.parametrize", "conftest.py", "pytest coverage", "python unit test" DO NOT…
  • 100pytest-fixtures
    Use when pytest fixtures, conftest files, parametrize decorators, and fixture scopes for comprehensive test setup.
  • 95pytest-skill
    Generates production-grade pytest tests in Python with fixtures, parametrize, markers, mocking, and conftest patterns. Use when user mentions "pytest", "conftest", "@pytest.fixture", "@pytest.mark", "Python test". Triggers on: "pytest", "conftest", "Python test", "parametrize", "Python unit test".
  • 100python-pytest-ops
    pytest testing patterns for Python. Triggers on: pytest, fixture, mark, parametrize, mock, conftest, test coverage, unit test, integration test, pytest.raises.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.