From c4dc7dc2f471d194d8a92d2795e2ae72347e78dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 13 Nov 2025 14:53:44 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Tweak=20test=20conditions=20for=20P?= =?UTF-8?q?ydantic=20v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_schema_ref_pydantic_v2.py | 35 ++++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/tests/test_schema_ref_pydantic_v2.py b/tests/test_schema_ref_pydantic_v2.py index 950c5c44b..119b76a52 100644 --- a/tests/test_schema_ref_pydantic_v2.py +++ b/tests/test_schema_ref_pydantic_v2.py @@ -1,39 +1,38 @@ -import sys from typing import Any +import pytest from fastapi import FastAPI from fastapi.testclient import TestClient from inline_snapshot import snapshot - -from tests.utils import skip_module_if_py_gte_314 - -if sys.version_info >= (3, 14): - skip_module_if_py_gte_314() - from pydantic import BaseModel, ConfigDict, Field -app = FastAPI() - +from tests.utils import needs_pydanticv2 -class ModelWithRef(BaseModel): - ref: str = Field(validation_alias="$ref", serialization_alias="$ref") - model_config = ConfigDict(validate_by_alias=True, serialize_by_alias=True) +@pytest.fixture(name="client") +def get_client(): + app = FastAPI() -@app.get("/", response_model=ModelWithRef) -async def read_root() -> Any: - return {"$ref": "some-ref"} + class ModelWithRef(BaseModel): + ref: str = Field(validation_alias="$ref", serialization_alias="$ref") + model_config = ConfigDict(validate_by_alias=True, serialize_by_alias=True) + @app.get("/", response_model=ModelWithRef) + async def read_root() -> Any: + return {"$ref": "some-ref"} -client = TestClient(app) + client = TestClient(app) + return client -def test_get(): +@needs_pydanticv2 +def test_get(client: TestClient): response = client.get("/") assert response.json() == {"$ref": "some-ref"} -def test_openapi_schema(): +@needs_pydanticv2 +def test_openapi_schema(client: TestClient): response = client.get("openapi.json") assert response.json() == snapshot( {