Coverage for src/pytest_cases/pep492.py: 45%

23 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 PEP492 "Coroutines with async and await syntax" 

7 

8from makefun import wraps 

9from .fixture_core1_unions import is_used_request, NOT_USED 

10 

11 

12def _ignore_unused_coroutine_pep492(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 return await fixture_func(*args, **kwargs) 

18 else: 

19 return NOT_USED 

20 

21 return wrapped_fixture_func 

22 

23def _decorate_fixture_plus_coroutine_pep492(fixture_func, new_sig, map_arguments): 

24 @wraps(fixture_func, new_sig=new_sig) 

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

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

27 return NOT_USED 

28 else: 

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

30 return await fixture_func(*_args, **_kwargs) 

31 

32 return wrapped_fixture_func 

33 

34 

35def _parametrize_plus_decorate_coroutine_pep492( 

36 test_func, 

37 new_sig, 

38 fixture_union_name, 

39 replace_paramfixture_with_values 

40): 

41 @wraps(test_func, new_sig=new_sig) 

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

43 if kwargs.get(fixture_union_name, None) is NOT_USED: 43 ↛ 46line 43 didn't jump to line 46, because the condition on line 43 was never true

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

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

46 return NOT_USED 

47 else: 

48 replace_paramfixture_with_values(kwargs) 

49 return await test_func(*args, **kwargs) 

50 

51 return wrapped_test_func