pytest_cases/fixture_parametrize_plus.py
def _fixture_product(caller_module,
                     name,                # type: str
                     fixtures_or_values,
                     fixture_positions,
                     scope="function",    # type: str
                     ids=None,            # type: Union[Callable, List[str]]
                     unpack_into=None,    # type: Iterable[str]
                     autouse=False,       # type: bool
                     hook=None,           # type: Callable[[Callable], Callable]
                     caller=None,         # type: Callable
                     **kwargs):
    """
    Internal implementation for fixture products created by pytest parametrize plus.

    :param caller_module:
    :param name:
    :param fixtures_or_values:
    :param fixture_positions:
    :param idstyle:
    :param scope:
    :param ids:
    :param unpack_into:
    :param autouse:
    :param kwargs:
    :return:
    """
    # test the `fixtures` argument to avoid common mistakes
    if not isinstance(fixtures_or_values, (tuple, set, list)):
        raise TypeError("fixture_product: the `fixtures_or_values` argument should be a tuple, set or list")
    else:
        has_lazy_vals = any(is_lazy_value(v) for v in fixtures_or_values)

    _tuple_size = len(fixtures_or_values)

    # first get all required fixture names
    f_names = [None] * _tuple_size
    for f_pos in fixture_positions:
        # possibly get the fixture name if the fixture symbol was provided
        f = fixtures_or_values[f_pos]
        if isinstance(f, fixture_ref):
            f = f.fixture
        # and remember the position in the tuple
        f_names[f_pos] = get_fixture_name(f)

    # remove duplicates by making it an ordered set
    all_names = remove_duplicates((n for n in f_names if n is not None))
    if len(all_names) < 1:
        raise ValueError("Empty fixture products are not permitted")

    def _tuple_generator(all_fixtures):
        for i in range(_tuple_size):
            fix_at_pos_i = f_names[i]
            if fix_at_pos_i is None:
                # fixed value
                # note: wouldnt it be almost as efficient but more readable to *always* call handle_lazy_args?
                yield get_lazy_args(fixtures_or_values[i]) if has_lazy_vals else fixtures_or_values[i]
            else:
                # fixture value
                yield all_fixtures[fix_at_pos_i]

    # then generate the body of our product fixture. It will require all of its dependent fixtures
    @with_signature("(%s)" % ', '.join(all_names))
    def _new_fixture(**all_fixtures):
        return tuple(_tuple_generator(all_fixtures))

    _new_fixture.__name__ = name

    # finally create the fixture per se.
    # WARNING we do not use pytest.fixture but fixture_plus so that NOT_USED is discarded
    f_decorator = fixture_plus(scope=scope, autouse=autouse, ids=ids, hook=hook, **kwargs)
    fix = f_decorator(_new_fixture)

    # Dynamically add fixture to caller's module as explained in https://github.com/pytest-dev/pytest/issues/2424
    check_name_available(caller_module, name, if_name_exists=WARN, caller=caller)
    setattr(caller_module, name, fix)

    # if unpacking is requested, do it here
    if unpack_into is not None:
        _make_unpack_fixture(caller_module, argnames=unpack_into, fixture=name, hook=hook)

    return fix

    Internal implementation for fixture products created by pytest parametrize plus.

    :param caller_module:
    :param name:
    :param fixtures_or_values:
    :param fixture_positions:
    :param idstyle:
    :param scope:
    :param ids:
    :param unpack_into:
    :param autouse:
    :param kwargs:
    :return:
    
Internal implementation for fixture products created by pytest parametrize plus.
Internal implementation for fixture products created by pytest parametrize plus .
def _fixture_product(caller_module,
                     name,                
                     fixtures_or_values,
                     fixture_positions,
                     scope="function",    
                     ids=None,            
                     unpack_into=None,    
                     autouse=False,       
                     hook=None,           
                     caller=None,         
                     **kwargs):
    if not isinstance(fixtures_or_values, (tuple, set, list)):
        raise TypeError("fixture_product: the `fixtures_or_values` argument should be a tuple, set or list")
    else:
        has_lazy_vals = any(is_lazy_value(v) for v in fixtures_or_values)
    _tuple_size = len(fixtures_or_values)
    f_names = [None] * _tuple_size
    for f_pos in fixture_positions:
        f = fixtures_or_values[f_pos]
        if isinstance(f, fixture_ref):
            f = f.fixture
        f_names[f_pos] = get_fixture_name(f)
    all_names = remove_duplicates((n for n in f_names if n is not None))
    if len(all_names) < 1:
        raise ValueError("Empty fixture products are not permitted")
    def _tuple_generator(all_fixtures):
        for i in range(_tuple_size):
            fix_at_pos_i = f_names[i]
            if fix_at_pos_i is None:
                yield get_lazy_args(fixtures_or_values[i]) if has_lazy_vals else fixtures_or_values[i]
            else:
                yield all_fixtures[fix_at_pos_i]
    @with_signature("(%s)" % ', '.join(all_names))
    def _new_fixture(**all_fixtures):
        return tuple(_tuple_generator(all_fixtures))
    _new_fixture.__name__ = name
    f_decorator = fixture_plus(scope=scope, autouse=autouse, ids=ids, hook=hook, **kwargs)
    fix = f_decorator(_new_fixture)
    check_name_available(caller_module, name, if_name_exists=WARN, caller=caller)
    setattr(caller_module, name, fix)
    if unpack_into is not None:
        _make_unpack_fixture(caller_module, argnames=unpack_into, fixture=name, hook=hook)
    return fix
def _fixture_product ( caller_module , name , fixtures_or_values , fixture_positions , scope = "function" , ids = None , unpack_into = None , autouse = False , hook = None , caller = None , ** kwargs ) : if not isinstance ( fixtures_or_values , ( tuple , set , list ) ) : raise TypeError ( "fixture_product: the `fixtures_or_values` argument should be a tuple, set or list" ) else : has_lazy_vals = any ( is_lazy_value ( v ) for v in fixtures_or_values ) _tuple_size = len ( fixtures_or_values ) f_names = [ None ] * _tuple_size for f_pos in fixture_positions : f = fixtures_or_values [ f_pos ] if isinstance ( f , fixture_ref ) : f = f . fixture f_names [ f_pos ] = get_fixture_name ( f ) all_names = remove_duplicates ( ( n for n in f_names if n is not None ) ) if len ( all_names ) < 1 : raise ValueError ( "Empty fixture products are not permitted" ) def _tuple_generator ( all_fixtures ) : for i in range ( _tuple_size ) : fix_at_pos_i = f_names [ i ] if fix_at_pos_i is None : yield get_lazy_args ( fixtures_or_values [ i ] ) if has_lazy_vals else fixtures_or_values [ i ] else : yield all_fixtures [ fix_at_pos_i ] @ with_signature ( "(%s)" % ', ' . join ( all_names ) ) def _new_fixture ( ** all_fixtures ) : return tuple ( _tuple_generator ( all_fixtures ) ) _new_fixture . __name__ = name f_decorator = fixture_plus ( scope = scope , autouse = autouse , ids = ids , hook = hook , ** kwargs ) fix = f_decorator ( _new_fixture ) check_name_available ( caller_module , name , if_name_exists = WARN , caller = caller ) setattr ( caller_module , name , fix ) if unpack_into is not None : _make_unpack_fixture ( caller_module , argnames = unpack_into , fixture = name , hook = hook ) return fix
Internal implementation for fixture products created by pytest parametrize plus.
Internal implementation for fixture products created by pytest parametrize plus .
# type: str # type: str # type: Union[Callable, List[str]] # type: Iterable[str] # type: bool # type: Callable[[Callable], Callable] # type: Callable """
    Internal implementation for fixture products created by pytest parametrize plus.

    :param caller_module:
    :param name:
    :param fixtures_or_values:
    :param fixture_positions:
    :param idstyle:
    :param scope:
    :param ids:
    :param unpack_into:
    :param autouse:
    :param kwargs:
    :return:
    """ # test the `fixtures` argument to avoid common mistakes # first get all required fixture names # possibly get the fixture name if the fixture symbol was provided # and remember the position in the tuple # remove duplicates by making it an ordered set # fixed value # note: wouldnt it be almost as efficient but more readable to *always* call handle_lazy_args? # fixture value # then generate the body of our product fixture. It will require all of its dependent fixtures # finally create the fixture per se. # WARNING we do not use pytest.fixture but fixture_plus so that NOT_USED is discarded # Dynamically add fixture to caller's module as explained in https://github.com/pytest-dev/pytest/issues/2424 # if unpacking is requested, do it here
None
caller_module
None
name
None
fixtures_or_values
None
fixture_positions
None
scope
None
ids
None
unpack_into
None
autouse
None
hook
caller
idstyle
None
kwargs
None