Skip to content
Back to skills

Python Testing

ASecurity

Use when writing or reviewing Python tests — pytest suite structure and naming, fixtures and conftest.py placement, parametrization, and coverage configuration and expectations.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentpythongotestingdocumentation

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add missing-bits/claude-plugins --skill python-testing --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Python Testing?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Python Testing
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/missing-bits-python-testing/badge)](https://www.skillsdirectory.com/skills/missing-bits-python-testing)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: python-testing
description: Use when writing or reviewing Python tests — pytest suite structure and naming, fixtures and conftest.py placement, parametrization, and coverage configuration and expectations.
---

# Python testing

pytest standards. Cite rules in review findings as
`(standard: python-testing, rule: <id>)`. Each rule names its source:
a pytest documentation page, a CPython doc, or `this standard` (a
recorded house decision). Everything runs via `uv run pytest`.

## Suite structure

- `tests/` sits beside `src/` and mirrors the package: code in
  `src/pkg/profiles/loader.py` is tested in
  `tests/profiles/test_loader.py`. (id: `test-mirror`; severity: minor;
  source: pytest docs "Good Integration Practices"; the mirror rule is
  this standard)
- Files are `test_<module>.py`; functions `test_<behavior>` named for
  the behavior, not the method (`test_missing_profile_raises`, not
  `test_load_2`). (id: `test-naming`; severity: minor; source: pytest
  docs "Conventions for Python test discovery"; behavior-naming is this
  standard)
- No logic in `tests/__init__.py`; shared helpers live in fixtures or
  plain modules imported explicitly. (id: `test-no-init-logic`;
  severity: minor; source: this standard)
- Slow or environment-needing tests carry a marker (e.g.
  `@pytest.mark.integration`) declared in `[tool.pytest.ini_options]
  markers` — the default run stays fast. (id: `test-markers`; severity:
  minor; source: pytest docs "How to mark test functions with
  attributes")

## Fixtures

- **Scope discipline**: function scope is the default; wider scopes
  (session, module) only for genuinely expensive, read-only resources —
  a session-scoped mutable fixture is a test-pollution bug waiting.
  (id: `test-fixture-scope`; severity: important; source: pytest docs
  "Fixtures" — scope section; the mutable-wide-scope ban is this
  standard)
- **conftest.py at the nearest common ancestor** of its consumers —
  never one giant root conftest. (id: `test-conftest-placement`;
  severity: minor; source: pytest docs — conftest.py fixture sharing;
  the nearest-ancestor rule is this standard)
- **Factory fixtures over module-level state**: a fixture returns a
  builder (`make_profile(**overrides)`) so each test states what it
  cares about. (id: `test-factories`; severity: minor; source: pytest
  docs "Factories as fixtures")
- `autouse=True` is rare and always carries a comment saying why every
  test needs it. Examples: [reference/conftest.py](reference/conftest.py).
  (id: `test-autouse-rare`; severity: minor; source: pytest docs —
  autouse fixtures; the rarity-plus-comment rule is this standard)

## Parametrization

`pytest.mark.parametrize` with explicit `ids=` when cases are the same
behavior over different inputs; separate test functions when the
BEHAVIOR differs (different asserts = different test). Examples:
[reference/test-patterns.py](reference/test-patterns.py).
(id: `test-parametrize`; severity: minor; source: pytest docs "How to
parametrize fixtures and test functions"; the same-behavior boundary is
this standard)

## Mocking

Mock only at boundaries the code does not own (network, clock,
subprocess); prefer a fake or a real temp resource over a mock when
cheap. Never patch internals of the unit under test — that pins the
implementation, not the behavior. (id: `test-mock-boundaries`;
severity: important; source: CPython `unittest.mock` docs, "Where to
patch"; the boundaries-you-do-not-own rule is this standard)

## Coverage

Measured with pytest-cov (`uv run pytest --cov=src`); new and changed
code ships with tests covering its behavior — reviewers judge coverage
of the CHANGE, not the historical total. A numeric repo-wide gate is a
per-project decision recorded in `pyproject.toml`, not assumed.
(id: `test-coverage-of-change`; severity: important; source: this
standard — a recorded developer decision, 2026-07-17)

Files in this skill

  • SKILL.md3.8 KB
  • reference/conftest.py1 KB
  • reference/test-patterns.py915 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.