Coverage for src/pytest_cases/pep380.py: 93%
23 statements
« prev ^ index » next coverage.py v7.2.7, created at 2024-09-26 21:52 +0000
« 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>
6# contains syntax illegal before PEP380 'Syntax for Delegating to a Subgenerator'
8from makefun import wraps
9from .fixture_core1_unions import is_used_request, NOT_USED
12def _ignore_unused_generator_pep380(fixture_func, new_sig, func_needs_request):
13 @wraps(fixture_func, new_sig=new_sig)
14 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 yield from fixture_func(*args, **kwargs)
18 else:
19 yield NOT_USED
21 return wrapped_fixture_func
23def _decorate_fixture_plus_generator_pep380(fixture_func, new_sig, map_arguments):
24 @wraps(fixture_func, new_sig=new_sig)
25 def wrapped_fixture_func(*_args, **_kwargs):
26 if not is_used_request(_kwargs['request']):
27 yield NOT_USED
28 else:
29 _args, _kwargs = map_arguments(*_args, **_kwargs)
30 yield from fixture_func(*_args, **_kwargs)
32 return wrapped_fixture_func
34def _parametrize_plus_decorate_generator_pep380(
35 test_func,
36 new_sig,
37 fixture_union_name,
38 replace_paramfixture_with_values
39):
40 @wraps(test_func, new_sig=new_sig)
41 def wrapped_test_func(*args, **kwargs): # noqa
42 if kwargs.get(fixture_union_name, None) is NOT_USED: 42 ↛ 45line 42 didn't jump to line 45, because the condition on line 42 was never true
43 # TODO why this ? it is probably useless: this fixture
44 # is private and will never end up in another union
45 yield NOT_USED
46 else:
47 replace_paramfixture_with_values(kwargs)
48 yield from test_func(*args, **kwargs)
50 return wrapped_test_func