From 2ed93650a1330b799755f9ebea2b4341bf013cfa Mon Sep 17 00:00:00 2001 From: valbort Date: Fri, 22 May 2026 13:44:57 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Update=20tests=20for=20Pydantic=20v?= =?UTF-8?q?2=20JSON=20decode=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we bypass json.loads and parse bytes directly via Pydantic, the JSON decode errors now return standard Pydantic v2 validation errors. Tests have been updated to expect this cleaner format. --- tests/test_tutorial/test_body/test_tutorial001.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_tutorial/test_body/test_tutorial001.py b/tests/test_tutorial/test_body/test_tutorial001.py index 8c883708a3..dea070e8b7 100644 --- a/tests/test_tutorial/test_body/test_tutorial001.py +++ b/tests/test_tutorial/test_body/test_tutorial001.py @@ -147,10 +147,10 @@ def test_post_broken_body(client: TestClient): "detail": [ { "type": "json_invalid", - "loc": ["body", 1], - "msg": "JSON decode error", - "input": {}, - "ctx": {"error": "Expecting property name enclosed in double quotes"}, + "loc": ["body"], + "msg": "Invalid JSON: key must be a string at line 1 column 2", + "input": "{some broken json}", + "ctx": {"error": "key must be a string at line 1 column 2"}, } ] } @@ -246,7 +246,7 @@ def test_wrong_headers(client: TestClient): def test_other_exceptions(client: TestClient): - with patch("json.loads", side_effect=Exception): + with patch("fastapi.routing.Request.body", side_effect=Exception): response = client.post("/items/", json={"test": "test2"}) assert response.status_code == 400, response.text