⬅ pytest_cases/pep380.py source

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 PEP380 'Syntax for Delegating to a Subgenerator'
7  
8 from makefun import wraps
9 from .fixture_core1_unions import is_used_request, NOT_USED
10  
11  
12 def _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
20  
21 return wrapped_fixture_func
22  
  • E302 Expected 2 blank lines, found 1
23 def _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)
31  
32 return wrapped_fixture_func
33  
  • E302 Expected 2 blank lines, found 1
34 def _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:
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)
49  
50 return wrapped_test_func