Skip to content

require-typed-http-test-response

HTTP tests must validate JSON response bodies into named models before asserting fields.

Why

Raw dictionary assertions duplicate wire spelling and do not prove that the complete response contract validates.

Fix

Parse response.json() once with ResponseModel.model_validate(...) or a Pydantic TypeAdapter, then assert typed attributes.

Examples

Before — flagged A test indexes an unvalidated response body
tests/test_cards.py
def test_interaction(client):
response = client.post("/actions")
assert response.json()["interactionId"]
After — preferred A test validates its response model
tests/test_cards.py
def test_interaction(client):
response = client.post("/actions")
body = InteractionResponse.model_validate(response.json())
assert body.interaction_id