Coverage for tests/utils.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-12-04 08:29 +0000

1import sys 1bcdefga

2 

3import pytest 1bcdefga

4from fastapi._compat import PYDANTIC_V2 1bcdefga

5from inline_snapshot import Snapshot 1bcdefga

6 

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

8needs_py310 = pytest.mark.skipif( 1bcdefga

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

10) 

11needs_py_lt_314 = pytest.mark.skipif( 1bcdefga

12 sys.version_info > (3, 13), reason="requires python3.13-" 

13) 

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

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

16 

17 

18def skip_module_if_py_gte_314(): 1bcdefga

19 """Skip entire module on Python 3.14+ at import time.""" 

20 if sys.version_info >= (3, 14): 1a

21 pytest.skip("requires python3.13-", allow_module_level=True) 1a

22 

23 

24def pydantic_snapshot( 1bcdefga

25 *, 

26 v2: Snapshot, 

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

28): 

29 """ 

30 This function should be used like this: 

31 

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

33 

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

35 

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

37 

38 >>> assert value == snapshot({ 

39 "data": "some data", 

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

41 }) 

42 """ 

43 return v2 if PYDANTIC_V2 else v1 2h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdbebfbgbhbibjbkblbmbnbobpbqb