Skip to content

Commit a7b2a68

Browse files
docs: Expand testing guidelines for exception groups and context managers
- Updated `AGENTS.md` and `TESTING_GUIDELINES.md` with instructions on handling `ExceptionGroup` subclasses like `PdfRestErrorGroup` in tests. - Emphasized verifying individual errors within `ExceptionGroups` using `pytest.RaisesGroup` and the `check=` hook for improved test accuracy. - Added guidance to use a single `with` statement for combined context managers in compliance with ruff's SIM117 rule. Assisted-by: Codex
1 parent ef72e06 commit a7b2a68

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

AGENTS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,21 @@
138138
- Write pytest tests: files named `test_*.py`, test functions `test_*`, fixtures
139139
in `conftest.py` where shared.
140140

141+
- Follow ruff’s SIM117 rule: when combining context managers (e.g., a client and
142+
`pytest.RaisesGroup`), use a single `with (...)` statement instead of nesting
143+
them to keep tests idiomatic and lint-clean.
144+
141145
- Cover both client transports in every new test module (unit and live suites):
142146
add distinct test cases (not parameterized branches) that exercise each
143147
assertion through `PdfRestClient` and `AsyncPdfRestClient` so sync/async
144148
behaviour stays independently verifiable.
145149

150+
- When endpoints may raise `PdfRestErrorGroup` (or any future pdfRest-specific
151+
exception groups), assert them with `pytest.RaisesGroup`/`pytest.RaisesExc`,
152+
and use the `check=` hook to confirm the outer group is the expected class so
153+
each inner error is validated individually rather than matching the group
154+
message alone.
155+
146156
- Ensure high-value coverage of public functions and edge cases; document intent
147157
in test docstrings when non-obvious.
148158

TESTING_GUIDELINES.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,16 @@ iteration required.
222222
- Local validation failures (`ValidationError`, `ValueError`) that should
223223
prevent HTTP calls.
224224
- Server/transport failures (`PdfRestApiError`, `PdfRestAuthenticationError`,
225-
`PdfRestTimeoutError`, `PdfRestTransportError`).
225+
`PdfRestTimeoutError`, `PdfRestTransportError`, `PdfRestErrorGroup`, etc.).
226226
- When behaviour should short-circuit locally (bad UUIDs, empty query lists,
227227
missing profiles), configure the transport to raise if invoked so the test
228228
proves no HTTP request occurs.
229+
- When endpoints intentionally raise pdfRest-specific `ExceptionGroup`
230+
subclasses (such as `PdfRestErrorGroup` produced by delete failures), capture
231+
them with `pytest.RaisesGroup`/`pytest.RaisesExc`, and use the `check=` hook
232+
to assert the aggregate is the expected group class. This verifies both the
233+
group message and each individual member (`PdfRestDeleteError`, future custom
234+
errors) instead of relying on the aggregate text alone.
229235

230236
## Additional Expectations
231237

0 commit comments

Comments
 (0)