- Subtotal assertions
- Exception assertions
Test subject.reserve(ids, new_id). It returns a new list with the ID appended, preserves its input, and raises ValueError("duplicate") for an existing ID. Use subject.NAME as the supplied record ID.
- Function-scoped fixtures
Create a function-scoped pytest fixture named store from subject.make_store(). Check an initially empty store and isolation between two stores. A previous test must not leave a record in a later test.
- Temporary file fixtures
Test subject.write_report(path, text) using tmp_path. It writes the exact Unicode text plus one newline in UTF-8, replacing an older report. Assert the file contents after two writes.
- Parameterized boundary table
Use pytest.mark.parametrize to test subject.accept_age(value). The inclusive allowed range is subject.LOW through subject.HIGH. Check the values immediately below, on, and above both bounds.
- Decimal rounding cases
Parametrize subject.round_units(text): parse Decimal text and round to a whole fictional unit with ROUND_HALF_UP. Test positive and negative half values plus an exact integer derived from subject.VALUE.
- Environment monkeypatch
Use monkeypatch to test subject.queue_name(). Read REPAIR_QUEUE, default to repairs only when absent, and preserve an explicitly empty setting. Test the supplied subject.NAME too.
- Mocked retry outcomes
Test subject.deliver(send). Retry once after TimeoutError, return the successful value, and let a second timeout escape. Use Mock(side_effect=...) so no service is contacted.
- ASGI lookup response
Write an async pytest test using AsyncClient and ASGITransport(app=subject.app). GET /repairs/{id} returns {"id": id} for subject.NAME; other IDs return 404 with detail missing. Assert both status and JSON.
- Dependency override cleanup
Test GET /queue on subject.app. Its async queue dependency normally returns repairs. Override it with an async fake returning subject.NAME, assert the changed body, then clear the override in finally and assert the default body.
- pyproject metadata parsing
Test subject.read_project(text) using real tomllib. Return [project].name and requires-python. Preserve an explicitly empty name; missing requires-python defaults to >=3.14. Use a TOML string with subject.NAME.
- Registered pytest markers
Test subject.marker_names(text) on [tool.pytest.ini_options].markers. Return the name before the first colon, stripped, in declaration order. A marker without a colon is valid. Missing markers give an empty list.