Coverage for tests/serializers/pydantic/test_compat.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-13 05:19 +0000

1from typing import Any 1klabmcndoefghij

2 

3from pydantic import BaseModel 1klabmcndoefghij

4 

5from fast_depends.pydantic._compat import get_model_fields 1klabmcndoefghij

6from tests.marks import pydanticV2 1klabmcndoefghij

7 

8 

9class Model(BaseModel): 1klabmcndoefghij

10 a: int 1klabmcndoe

11 

12 

13@pydanticV2 1klabmcndoefghij

14def test_get_model_fields_falls_back_to_model_fields() -> None: 1klabmcndoefghij

15 """Pydantic < 2.11 exposes no `__pydantic_fields__`, only the (now deprecated) 

16 `model_fields` attribute. 

17 """ 

18 

19 class WithoutPydanticFields: 1abcdefghij

20 model_fields: dict[str, Any] = dict(get_model_fields(Model)) 1abcdefghij

21 

22 assert get_model_fields(WithoutPydanticFields) == ( # type: ignore[arg-type] 1abcdefghij

23 WithoutPydanticFields.model_fields 

24 )