From 227cb85a03ec6522f641467fbf6af9bc5b1c2e75 Mon Sep 17 00:00:00 2001 From: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com> Date: Mon, 9 Feb 2026 16:35:43 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Fix=20parameterized=20tests=20with?= =?utf8?q?=20snapshots=20(#14875)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../test_path/test_required_str.py | 6 +-- ...est_tutorial001_tutorial002_tutorial003.py | 4 +- ...est_tutorial002_tutorial003_tutorial004.py | 4 +- .../test_tutorial003_tutorial004.py | 4 +- .../test_tutorial010.py | 39 +++++++++---------- 5 files changed, 28 insertions(+), 29 deletions(-) diff --git a/tests/test_request_params/test_path/test_required_str.py b/tests/test_request_params/test_path/test_required_str.py index 5add058c2..aecc2eb6c 100644 --- a/tests/test_request_params/test_path/test_required_str.py +++ b/tests/test_request_params/test_path/test_required_str.py @@ -3,7 +3,7 @@ from typing import Annotated import pytest from fastapi import FastAPI, Path from fastapi.testclient import TestClient -from inline_snapshot import snapshot +from inline_snapshot import Is, snapshot app = FastAPI() @@ -58,8 +58,8 @@ def test_schema(path: str, expected_name: str, expected_title: str): [ { "required": True, - "schema": {"title": expected_title, "type": "string"}, - "name": expected_name, + "schema": {"title": Is(expected_title), "type": "string"}, + "name": Is(expected_name), "in": "path", } ] diff --git a/tests/test_tutorial/test_body_nested_models/test_tutorial001_tutorial002_tutorial003.py b/tests/test_tutorial/test_body_nested_models/test_tutorial001_tutorial002_tutorial003.py index 78e5e53a2..18bce279b 100644 --- a/tests/test_tutorial/test_body_nested_models/test_tutorial001_tutorial002_tutorial003.py +++ b/tests/test_tutorial/test_body_nested_models/test_tutorial001_tutorial002_tutorial003.py @@ -3,7 +3,7 @@ import importlib import pytest from dirty_equals import IsList from fastapi.testclient import TestClient -from inline_snapshot import snapshot +from inline_snapshot import Is, snapshot from ...utils import needs_py310 @@ -212,7 +212,7 @@ def test_openapi_schema(client: TestClient, mod_name: str): "title": "Tax", "anyOf": [{"type": "number"}, {"type": "null"}], }, - "tags": tags_schema, + "tags": Is(tags_schema), }, "required": [ "name", diff --git a/tests/test_tutorial/test_custom_response/test_tutorial002_tutorial003_tutorial004.py b/tests/test_tutorial/test_custom_response/test_tutorial002_tutorial003_tutorial004.py index f79d38b83..68e046ac5 100644 --- a/tests/test_tutorial/test_custom_response/test_tutorial002_tutorial003_tutorial004.py +++ b/tests/test_tutorial/test_custom_response/test_tutorial002_tutorial003_tutorial004.py @@ -2,7 +2,7 @@ import importlib import pytest from fastapi.testclient import TestClient -from inline_snapshot import snapshot +from inline_snapshot import Is, snapshot @pytest.fixture( @@ -59,7 +59,7 @@ def test_openapi_schema(client: TestClient, mod_name: str): "responses": { "200": { "description": "Successful Response", - "content": response_content, + "content": Is(response_content), } }, "summary": "Read Items", diff --git a/tests/test_tutorial/test_path_operation_configurations/test_tutorial003_tutorial004.py b/tests/test_tutorial/test_path_operation_configurations/test_tutorial003_tutorial004.py index 8e86cd8a5..c13a3c38c 100644 --- a/tests/test_tutorial/test_path_operation_configurations/test_tutorial003_tutorial004.py +++ b/tests/test_tutorial/test_path_operation_configurations/test_tutorial003_tutorial004.py @@ -4,7 +4,7 @@ from textwrap import dedent import pytest from dirty_equals import IsList from fastapi.testclient import TestClient -from inline_snapshot import snapshot +from inline_snapshot import Is, snapshot from ...utils import needs_py310 @@ -75,7 +75,7 @@ def test_openapi_schema(client: TestClient, mod_name: str): "/items/": { "post": { "summary": "Create an item", - "description": DESCRIPTIONS[mod_name], + "description": Is(DESCRIPTIONS[mod_name]), "operationId": "create_item_items__post", "requestBody": { "content": { diff --git a/tests/test_tutorial/test_query_params_str_validations/test_tutorial010.py b/tests/test_tutorial/test_query_params_str_validations/test_tutorial010.py index 395f79518..efe9f1fa6 100644 --- a/tests/test_tutorial/test_query_params_str_validations/test_tutorial010.py +++ b/tests/test_tutorial/test_query_params_str_validations/test_tutorial010.py @@ -3,7 +3,7 @@ import importlib import pytest from fastapi._compat import PYDANTIC_VERSION_MINOR_TUPLE from fastapi.testclient import TestClient -from inline_snapshot import snapshot +from inline_snapshot import Is, snapshot from ...utils import needs_py310 @@ -66,6 +66,23 @@ def test_query_params_str_validations_item_query_nonregexquery(client: TestClien def test_openapi_schema(client: TestClient): response = client.get("/openapi.json") assert response.status_code == 200, response.text + + parameters_schema = { + "anyOf": [ + { + "type": "string", + "minLength": 3, + "maxLength": 50, + "pattern": "^fixedquery$", + }, + {"type": "null"}, + ], + "title": "Query string", + "description": "Query string for the items to search in the database that have a good match", + # See https://github.com/pydantic/pydantic/blob/80353c29a824c55dea4667b328ba8f329879ac9f/tests/test_fastapi.sh#L25-L34. + **({"deprecated": True} if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10) else {}), + } + assert response.json() == snapshot( { "openapi": "3.1.0", @@ -96,25 +113,7 @@ def test_openapi_schema(client: TestClient): "description": "Query string for the items to search in the database that have a good match", "required": False, "deprecated": True, - "schema": { - "anyOf": [ - { - "type": "string", - "minLength": 3, - "maxLength": 50, - "pattern": "^fixedquery$", - }, - {"type": "null"}, - ], - "title": "Query string", - "description": "Query string for the items to search in the database that have a good match", - # See https://github.com/pydantic/pydantic/blob/80353c29a824c55dea4667b328ba8f329879ac9f/tests/test_fastapi.sh#L25-L34. - **( - {"deprecated": True} - if PYDANTIC_VERSION_MINOR_TUPLE >= (2, 10) - else {} - ), - }, + "schema": Is(parameters_schema), "name": "item-query", "in": "query", } -- 2.47.3