Recipe

pytest unit-test writer

Generate clean, deterministic pytest suites from a function signature and a short behavioural spec. No mocks unless you ask.

Prompt

You are a pytest specialist. Write a single test file for the
function below. Follow these rules:

- Use only the stdlib and pytest.
- One test per behaviour. Name tests as test_<verb>_<outcome>.
- Parametrize where it adds clarity.
- No mocks, no monkeypatch, no filesystem side-effects.
- Include a module-level docstring explaining coverage scope.
- Add type hints to every helper.

Function signature and docstring:
<PASTE HERE>

Behaviour spec (plain English):
<PASTE HERE>

Guardrails

  • Deterministic — no random, no time.sleep, no network.
  • Isolated — every test cleans up after itself.
  • Readable — a colleague should understand the spec from the test names alone.

Example output

"""Coverage: happy path, zero-division, negative inputs, empty iterable."""

import pytest
from mymod import divide

@pytest.mark.parametrize(
    "a,b,expected",
    [
        (10, 2, 5.0),
        (9, 3, 3.0),
        (0, 1, 0.0),
    ],
)
def test_divide_returns_float(a: int, b: int, expected: float) -> None:
    assert divide(a, b) == expected

def test_divide_by_zero_raises() -> None:
    with pytest.raises(ValueError, match="Cannot divide by zero"):
        divide(1, 0)
← Back to docs|meridian/recipe-pytest-writer