diff --git a/tests/test_pydantic_v1_models.py b/tests/test_pydantic_v1_models.py index 35f0195cc..a719ee4b4 100644 --- a/tests/test_pydantic_v1_models.py +++ b/tests/test_pydantic_v1_models.py @@ -1,23 +1,37 @@ import pytest from fastapi import Body, FastAPI +from fastapi._compat import PYDANTIC_V2 from fastapi.exceptions import ResponseValidationError from fastapi.testclient import TestClient -from pydantic import v1 from typing_extensions import Annotated from tests.utils import needs_pydanticv2 +if PYDANTIC_V2: + from pydantic import v1 -class Item(v1.BaseModel): - name: str - description: str | None = None - price: float - tax: float | None = None - tags: list = [] + class Item(v1.BaseModel): + name: str + description: str | None = None + price: float + tax: float | None = None + tags: list = [] + class Model(v1.BaseModel): + name: str -class Model(v1.BaseModel): - name: str +else: + from pydantic import BaseModel + + class Item(BaseModel): + name: str + description: str | None = None + price: float + tax: float | None = None + tags: list = [] + + class Model(BaseModel): + name: str app = FastAPI()