From 93136c369862d42067346cbb5dbc1a261117bed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 18 Dec 2025 13:09:43 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Make=20benchmark=20tests=20run=20fo?= =?UTF-8?q?r=20both=20Pydantic=20v2=20and=20Pydantic=20v1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/benchmarks/test_general_performance.py | 54 +++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/tests/benchmarks/test_general_performance.py b/tests/benchmarks/test_general_performance.py index b2bd20336..e3bbacab3 100644 --- a/tests/benchmarks/test_general_performance.py +++ b/tests/benchmarks/test_general_performance.py @@ -5,29 +5,7 @@ from typing import Annotated, Any import pytest from fastapi import Depends, FastAPI from fastapi.testclient import TestClient -from pydantic import BaseModel - - -class ItemIn(BaseModel): - name: str - value: int - - -class ItemOut(BaseModel): - name: str - value: int - dep: int - - -class LargeIn(BaseModel): - items: list[dict[str, Any]] - metadata: dict[str, Any] - - -class LargeOut(BaseModel): - items: list[dict[str, Any]] - metadata: dict[str, Any] - +from pydantic import BaseModel, v1 LARGE_ITEMS: list[dict[str, Any]] = [ { @@ -61,8 +39,36 @@ def dep_b(a: Annotated[int, Depends(dep_a)]): return a + 2 +@pytest.fixture( + scope="module", + params=[ + pytest.param(BaseModel, id="pydantic-v2"), + pytest.param(v1.BaseModel, id="pydantic-v1"), + ], +) +def basemodel_class(request: pytest.FixtureRequest) -> type[Any]: + return request.param + + @pytest.fixture(scope="module") -def app() -> FastAPI: +def app(basemodel_class: type[Any]) -> FastAPI: + class ItemIn(basemodel_class): + name: str + value: int + + class ItemOut(basemodel_class): + name: str + value: int + dep: int + + class LargeIn(basemodel_class): + items: list[dict[str, Any]] + metadata: dict[str, Any] + + class LargeOut(basemodel_class): + items: list[dict[str, Any]] + metadata: dict[str, Any] + app = FastAPI() @app.post("/sync/validated", response_model=ItemOut)