Coverage for tests/utils.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-05 00:03 +0000

1import sys 1abcdef

2 

3import pytest 1abcdef

4from fastapi._compat import PYDANTIC_V2 1abcdef

5from inline_snapshot import Snapshot 1abcdef

6 

7needs_py39 = pytest.mark.skipif(sys.version_info < (3, 9), reason="requires python3.9+") 1abcdef

8needs_py310 = pytest.mark.skipif( 1abcdef

9 sys.version_info < (3, 10), reason="requires python3.10+" 

10) 

11needs_pydanticv2 = pytest.mark.skipif(not PYDANTIC_V2, reason="requires Pydantic v2") 1abcdef

12needs_pydanticv1 = pytest.mark.skipif(PYDANTIC_V2, reason="requires Pydantic v1") 1abcdef

13 

14 

15def pydantic_snapshot( 1abcdef

16 *, 

17 v2: Snapshot, 

18 v1: Snapshot, # TODO: remove v1 argument when deprecating Pydantic v1 

19): 

20 """ 

21 This function should be used like this: 

22 

23 >>> assert value == pydantic_snapshot(v2=snapshot(),v1=snapshot()) 

24 

25 inline-snapshot will create the snapshots when pytest is executed for each versions of pydantic. 

26 

27 It is also possible to use the function inside snapshots for version-specific values. 

28 

29 >>> assert value == snapshot({ 

30 "data": "some data", 

31 "version_specific": pydantic_snapshot(v2=snapshot(),v1=snapshot()), 

32 }) 

33 """ 

34 return v2 if PYDANTIC_V2 else v1 1ghijklmnopqr