Coverage for src/pytest_cases/pep525.py: 18%

26 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2024-09-26 21:52 +0000

1# Authors: Sylvain MARIE <sylvain.marie@se.com> 

2# + All contributors to <https://github.com/smarie/python-pytest-cases> 

3# 

4# License: 3-clause BSD, <https://github.com/smarie/python-pytest-cases/blob/master/LICENSE> 

5 

6# contains syntax illegal before PEP525 "Asynchronous Generators" 

7 

8from makefun import wraps 

9from .fixture_core1_unions import is_used_request, NOT_USED 

10 

11 

12def _ignore_unused_asyncgen_pep525(fixture_func, new_sig, func_needs_request): 

13 @wraps(fixture_func, new_sig=new_sig) 

14 async def wrapped_fixture_func(*args, **kwargs): 

15 request = kwargs['request'] if func_needs_request else kwargs.pop('request') 

16 if is_used_request(request): 

17 async for res in fixture_func(*args, **kwargs): 

18 yield res 

19 else: 

20 yield NOT_USED 

21 

22 return wrapped_fixture_func 

23 

24def _decorate_fixture_plus_asyncgen_pep525(fixture_func, new_sig, map_arguments): 

25 @wraps(fixture_func, new_sig=new_sig) 

26 async def wrapped_fixture_func(*_args, **_kwargs): 

27 if not is_used_request(_kwargs['request']): 

28 yield NOT_USED 

29 else: 

30 _args, _kwargs = map_arguments(*_args, **_kwargs) 

31 async for res in fixture_func(*_args, **_kwargs): 

32 yield res 

33 

34 return wrapped_fixture_func 

35 

36def _parametrize_plus_decorate_asyncgen_pep525( 

37 test_func, 

38 new_sig, 

39 fixture_union_name, 

40 replace_paramfixture_with_values 

41): 

42 @wraps(test_func, new_sig=new_sig) 

43 async def wrapped_test_func(*args, **kwargs): # noqa 

44 if kwargs.get(fixture_union_name, None) is NOT_USED: 

45 # TODO why this ? it is probably useless: this fixture 

46 # is private and will never end up in another union 

47 yield NOT_USED 

48 else: 

49 replace_paramfixture_with_values(kwargs) 

50 async for res in test_func(*args, **kwargs): 

51 yield res 

52 

53 return wrapped_test_func