Skip to content
Skills Library
Programming · Testing

python-testing

/python-testing

Python tests with pytest - layout, fixtures and conftest, parametrize, raises with match, tmp_path and monkeypatch, mocks with spec at the boundary, async tests, strict mode and warnings as errors, changed-lines coverage. Use when writing, fixing or setting up Python tests. Process and coverage threshold: tdd-workflow.

Licence
MIT
Last repository change
05.11.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.11.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

Python tests with pytest - layout, fixtures and conftest, parametrize, raises with match, tmp_path and monkeypatch, mocks with spec at the boundary, async tests, strict mode and warnings as errors, changed-lines coverage. Use when writing, fixing or setting up Python tests. Process and coverage threshold: tdd-workflow.

Original author description

Python tests with pytest - layout, fixtures and conftest, parametrize, raises with match, tmp_path and monkeypatch, mocks with spec at the boundary, async tests, strict mode and warnings as errors, changed-lines coverage. Use when writing, fixing or setting up Python tests. Process and coverage threshold: tdd-workflow.

How it works

  1. Layout
  2. Writing tests
  3. Doubles
  4. Async
  5. Strictness
  6. Commands
Original SKILL.md headings · 42 lines, 400 words
SKILL.md preview
---
name: python-testing
description: "Python tests with pytest - layout, fixtures and conftest, parametrize, raises with match, tmp_path and monkeypatch, mocks with spec at the boundary, async tests, strict mode and warnings as errors, changed-lines coverage. Use when writing, fixing or setting up Python tests. Process and coverage threshold: tdd-workflow."
---

# python-testing

Process and coverage threshold: `tdd-workflow`. Config (strict mode, warnings as errors, coverage): `python-tooling`.

## Layout

- Code in `src/<package>/`, tests in `tests/` outside it. Files `test_*.py`.
- Shared fixtures in `conftest.py` in the narrowest folder that needs them.

## Writing tests

- Plain `assert`; pytest shows the compared values on failure.
- Cases that differ only in data: one test with `@pytest.mark.parametrize`, readable names through `pytest.param(..., id="...")`. No loops over cases inside a test.
- Exceptions: `pytest.raises(ValueError, match="...")`; the `match` proves it is the expected failure.
- Fixtures for setup; teardown after `yield`; the narrowest scope that works; `autouse` only for safety nets that every test needs.
- Files in `tmp_path`; environment variables and attributes through `monkeypatch`. Never the real home directory, network or clock.

## Doubles

- Own code: real objects or simple fakes. Mocks only at the boundary (HTTP, message APIs, time).
- Mocks with a spec (`create_autospec`, `spec=`), so a wrong call or attribute fails.
- HTTP with httpx: hand the client an `httpx.MockTransport`; RESPX or pytest-httpx for complex cases. Don't patch the client's methods.
- A hand-written fake replaces the lowest boundary (the transport, `urlopen`), not your own wrapper around it: a fake of the wrapper keeps its old signature and passes after the wrapper and the code behind it stop matching. At least one test per outside service runs the real path down to that boundary.
- Time: pass a clock into the code, or patch the function it calls with `monkeypatch`.
- Dates in a local zone: add days to the local date, then attach the time. Days added to a UTC instant land an hour off when the clocks change.

## Async

- pytest-asyncio; in a project that uses only asyncio set `asyncio_mode = "auto"` in `[tool.pytest]`, which makes `async def` tests and fixtures run without markers.
- Projects on AnyIO: its own plugin (`anyio_mode = "auto"`); it conflicts with pytest-asyncio's auto mode, so never both.

## Strictness

- Unknown markers and config keys are errors; an `xfail` that passes fails the run, so a fixed bug forces the marker out.
- Warnings are errors; a test that expects one uses `pytest.warns`.

## Commands

- `uv run pytest -q`; one test: `uv run pytest tests/test_x.py::test_name`; stop at the first failure: `-x`.
- Coverage: `uv run pytest --cov`. Changed lines against the `tdd-workflow` threshold: `uv run diff-cover coverage.xml --compare-branch=origin/main --fail-under=<threshold>` after `--cov-report=xml`.

Versions

RepositoryScoreLicence
This page · ssvinar/senior-agent-skills90MIT
microsoft/agent-framework100MIT
Sanit-mann/The-Insectoids100MIT
jelvodev/yaap100MIT
aeondave/malskill100MIT
sophophilix/agent-skills100MIT
laurigates/claude-plugins100MIT
dmitriyyukhanov/agent-plugins100MIT
affaan-m/ECC100MIT

Database snapshot: 13.11.2026 · package version cd03ff4e9818 (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

  • 95python-testing-patterns
    Use when writing or reviewing Python tests - pytest fixtures, parametrize, conftest, mock/patch patterns, pytest-asyncio, hypothesis property-based testing, freezegun/time-machine, factory_boy, and coverage configuration.
  • 93pytest-patterns
    Python testing with pytest fixtures, parametrize, markers, conftest, mocking and temporary paths. Use when writing, reviewing or refactoring the pytest tests in this repository.
  • 100pytest-writing
    Write and review pytest tests for Python code in idiomatic pytest: fixtures with the right scope and yield teardown, parametrize with readable ids, pytest.raises with match, approx, tmp_path and monkeypatch for isolation from the real environment, test doubles that patch where a…
  • 100python-pytest-ops
    pytest testing patterns for Python. Triggers on: pytest, fixture, mark, parametrize, mock, conftest, test coverage, unit test, integration test, pytest.raises.
  • 100python-unit-tests
    Use for any question or task about Python tests, including quick how-to questions and tests for one function: pytest fixtures and conftest.py, parametrize, mocking, markers, slow or untrusted suites, coverage gates and CI. Has pytest 9 config and strict mode, subtests, and a…
  • 100testing-python
    Write and evaluate effective Python tests using pytest. Use when writing tests, reviewing test code, debugging test failures, or improving test coverage. Covers test design, fixtures, parameterization, mocking, async testing, and CI integration.

Feedback and reports

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