pytest_cases/fixture_parametrize_plus.py
def _create_params_alt(test_func_name, union_name, from_i, to_i, hook):  # noqa
            """ Routine that will be used to create a parameter fixture for argvalues between prev_i and i"""

            # check if this is about a single value or several values
            single_param_val = (to_i == from_i + 1)

            if single_param_val:
                i = from_i  # noqa

                # Create a unique fixture name
                p_fix_name = "%s_%s_P%s" % (test_func_name, param_names_str, i)
                p_fix_name = check_name_available(caller_module, p_fix_name, if_name_exists=CHANGE,
                                                  caller=parametrize_plus)

                if debug:
                    print("Creating fixture %r to handle parameter %s" % (p_fix_name, i))

                # Create the fixture that will return the unique parameter value ("auto-simplify" flag)
                # IMPORTANT that fixture is NOT parametrized so has no id nor marks: use argvalues not marked_argvalues
                _create_param_fixture(caller_module, argname=p_fix_name, argvalues=argvalues[i:i+1], hook=hook,
                                      auto_simplify=True)

                # Create the alternative
                argvals = (argvalues[i],) if nb_params == 1 else argvalues[i]
                p_fix_alt = SingleParamAlternative(union_name=union_name, alternative_name=p_fix_name,
                                                   argnames=argnames, argvalues_index=i, argvalues=argvals)
                # Finally copy the custom id/marks on the ParamAlternative if any
                if is_marked_parameter_value(marked_argvalues[i]):
                    p_fix_alt = pytest.param(p_fix_alt, id=marked_argvalues[i].id, marks=marked_argvalues[i].marks)

            else:
                # Create a unique fixture name
                p_fix_name = "%s_%s_is_P%stoP%s" % (test_func_name, param_names_str, from_i, to_i - 1)
                p_fix_name = check_name_available(caller_module, p_fix_name, if_name_exists=CHANGE,
                                                  caller=parametrize_plus)

                if debug:
                    print("Creating fixture %r to handle parameters %s to %s" % (p_fix_name, from_i, to_i - 1))

                # If an explicit list of ids was provided, slice it. Otherwise use the provided callable
                try:
                    param_ids = ids[from_i:to_i]
                except TypeError:
                    # callable ? otherwise default to a customized id maker that replaces the fixture name
                    # that we use (p_fix_name) with a simpler name in the ids (just the argnames)
                    param_ids = ids or _make_idfun_for_params(argnames=argnames, nb_positions=(to_i - from_i))

                # Create the fixture that will take ALL these parameter values (in a single parameter)
                # That fixture WILL be parametrized, this is why we propagate the param_ids and use the marked values
                if nb_params == 1:
                    _argvals = marked_argvalues[from_i:to_i]
                else:
                    # we have to create a tuple around the vals because we have a SINGLE parameter that is a tuple
                    _argvals = tuple(ParameterSet((vals, ), id=id, marks=marks or ())
                                     for vals, id, marks in zip(argvalues[from_i:to_i],
                                                                p_ids[from_i:to_i], p_marks[from_i:to_i]))
                _create_param_fixture(caller_module, argname=p_fix_name, argvalues=_argvals, ids=param_ids, hook=hook)

                # todo put back debug=debug above

                # Create the corresponding alternative
                p_fix_alt = MultiParamAlternative(union_name=union_name, alternative_name=p_fix_name, argnames=argnames,
                                                  argvalues_index_from=from_i, argvalues_index_to=to_i)
                # no need to copy the custom id/marks to the ParamAlternative: they were passed above already

            return p_fix_name, p_fix_alt
 Routine that will be used to create a parameter fixture for argvalues between prev_i and i
Routine that will be used to create a parameter fixture for argvalues between prev_i and i
Routine that will be used to create a parameter fixture for argvalues between prev_i and i
def _create_params_alt(test_func_name, union_name, from_i, to_i, hook):  
            single_param_val = (to_i == from_i + 1)
            if single_param_val:
                i = from_i  
                p_fix_name = "%s_%s_P%s" % (test_func_name, param_names_str, i)
                p_fix_name = check_name_available(caller_module, p_fix_name, if_name_exists=CHANGE,
                                                  caller=parametrize_plus)
                if debug:
                    print("Creating fixture %r to handle parameter %s" % (p_fix_name, i))
                _create_param_fixture(caller_module, argname=p_fix_name, argvalues=argvalues[i:i+1], hook=hook,
                                      auto_simplify=True)
                argvals = (argvalues[i],) if nb_params == 1 else argvalues[i]
                p_fix_alt = SingleParamAlternative(union_name=union_name, alternative_name=p_fix_name,
                                                   argnames=argnames, argvalues_index=i, argvalues=argvals)
                if is_marked_parameter_value(marked_argvalues[i]):
                    p_fix_alt = pytest.param(p_fix_alt, id=marked_argvalues[i].id, marks=marked_argvalues[i].marks)
            else:
                p_fix_name = "%s_%s_is_P%stoP%s" % (test_func_name, param_names_str, from_i, to_i - 1)
                p_fix_name = check_name_available(caller_module, p_fix_name, if_name_exists=CHANGE,
                                                  caller=parametrize_plus)
                if debug:
                    print("Creating fixture %r to handle parameters %s to %s" % (p_fix_name, from_i, to_i - 1))
                try:
                    param_ids = ids[from_i:to_i]
                except TypeError:
                    param_ids = ids or _make_idfun_for_params(argnames=argnames, nb_positions=(to_i - from_i))
                if nb_params == 1:
                    _argvals = marked_argvalues[from_i:to_i]
                else:
                    _argvals = tuple(ParameterSet((vals, ), id=id, marks=marks or ())
                                     for vals, id, marks in zip(argvalues[from_i:to_i],
                                                                p_ids[from_i:to_i], p_marks[from_i:to_i]))
                _create_param_fixture(caller_module, argname=p_fix_name, argvalues=_argvals, ids=param_ids, hook=hook)
                p_fix_alt = MultiParamAlternative(union_name=union_name, alternative_name=p_fix_name, argnames=argnames,
                                                  argvalues_index_from=from_i, argvalues_index_to=to_i)
            return p_fix_name, p_fix_alt
def _create_params_alt ( test_func_name , union_name , from_i , to_i , hook ) : single_param_val = ( to_i == from_i + 1 ) if single_param_val : i = from_i p_fix_name = "%s_%s_P%s" % ( test_func_name , param_names_str , i ) p_fix_name = check_name_available ( caller_module , p_fix_name , if_name_exists = CHANGE , caller = parametrize_plus ) if debug : print ( "Creating fixture %r to handle parameter %s" % ( p_fix_name , i ) ) _create_param_fixture ( caller_module , argname = p_fix_name , argvalues = argvalues [ i : i + 1 ] , hook = hook , auto_simplify = True ) argvals = ( argvalues [ i ] , ) if nb_params == 1 else argvalues [ i ] p_fix_alt = SingleParamAlternative ( union_name = union_name , alternative_name = p_fix_name , argnames = argnames , argvalues_index = i , argvalues = argvals ) if is_marked_parameter_value ( marked_argvalues [ i ] ) : p_fix_alt = pytest . param ( p_fix_alt , id = marked_argvalues [ i ] . id , marks = marked_argvalues [ i ] . marks ) else : p_fix_name = "%s_%s_is_P%stoP%s" % ( test_func_name , param_names_str , from_i , to_i - 1 ) p_fix_name = check_name_available ( caller_module , p_fix_name , if_name_exists = CHANGE , caller = parametrize_plus ) if debug : print ( "Creating fixture %r to handle parameters %s to %s" % ( p_fix_name , from_i , to_i - 1 ) ) try : param_ids = ids [ from_i : to_i ] except TypeError : param_ids = ids or _make_idfun_for_params ( argnames = argnames , nb_positions = ( to_i - from_i ) ) if nb_params == 1 : _argvals = marked_argvalues [ from_i : to_i ] else : _argvals = tuple ( ParameterSet ( ( vals , ) , id = id , marks = marks or ( ) ) for vals , id , marks in zip ( argvalues [ from_i : to_i ] , p_ids [ from_i : to_i ] , p_marks [ from_i : to_i ] ) ) _create_param_fixture ( caller_module , argname = p_fix_name , argvalues = _argvals , ids = param_ids , hook = hook ) p_fix_alt = MultiParamAlternative ( union_name = union_name , alternative_name = p_fix_name , argnames = argnames , argvalues_index_from = from_i , argvalues_index_to = to_i ) return p_fix_name , p_fix_alt
Routine that will be used to create a parameter fixture for argvalues between prev_i and i
Routine that will be used to create a parameter fixture for argvalues between prev_i and i
# noqa """ Routine that will be used to create a parameter fixture for argvalues between prev_i and i""" # check if this is about a single value or several values # noqa # Create a unique fixture name # Create the fixture that will return the unique parameter value ("auto-simplify" flag) # IMPORTANT that fixture is NOT parametrized so has no id nor marks: use argvalues not marked_argvalues # Create the alternative # Finally copy the custom id/marks on the ParamAlternative if any # Create a unique fixture name # If an explicit list of ids was provided, slice it. Otherwise use the provided callable # callable ? otherwise default to a customized id maker that replaces the fixture name # that we use (p_fix_name) with a simpler name in the ids (just the argnames) # Create the fixture that will take ALL these parameter values (in a single parameter) # That fixture WILL be parametrized, this is why we propagate the param_ids and use the marked values # we have to create a tuple around the vals because we have a SINGLE parameter that is a tuple # todo put back debug=debug above # Create the corresponding alternative # no need to copy the custom id/marks to the ParamAlternative: they were passed above already
test_func_name
union_name
from_i
to_i
hook