How to use iter_parametrization_fixtures method in Slash

Best Python code snippet using slash

fixture_store.py

Source:fixture_store.py Github

copy

Full Screen

...69 def get_required_fixture_names(self, test_func):70 """Returns a list of fixture names needed by test_func.71 Each element returned is either a string or a tuple of (required_name, real_name)72 """73 skip_names = {name for name, _ in iter_parametrization_fixtures(test_func)}74 returned = []75 for argument in get_arguments(test_func):76 if argument.name in skip_names:77 continue78 real_name = get_real_fixture_name_from_argument(argument)79 if real_name == argument.name:80 returned.append(real_name)81 else:82 returned.append((argument.name, real_name))83 return returned84 def get_required_fixture_objects(self, test_func, namespace):85 names = self.get_required_fixture_names(test_func)86 assert isinstance(names, list)87 return set(self.get_fixture_dict(names, namespace=namespace, get_values=False).values())88 def resolve_name(self, parameter_name, start_point, namespace=None):89 if namespace is None:90 namespace = self.get_current_namespace()91 parts = parameter_name.split('.')[::-1]92 if not parts:93 raise UnknownFixtures(parameter_name)94 while parts:95 current_name = parts.pop()96 param_fixtures = dict(iter_parametrization_fixtures(start_point))97 if current_name in param_fixtures:98 if parts: # we cannot decend further than a parameter99 raise UnknownFixtures(parameter_name)100 start_point = param_fixtures[current_name]101 else:102 start_point = self.get_fixture_by_name(current_name, namespace=namespace)103 namespace = start_point.namespace104 return start_point105 def __iter__(self):106 return iter(self._fixtures_by_id.values())107 def push_namespace(self):108 self._namespaces.append(Namespace(self, parent=self._namespaces[-1]))109 def pop_namespace(self):110 return self._namespaces.pop(-1)...

Full Screen

Full Screen

test_fixture_mechanism.py

Source:test_fixture_mechanism.py Github

copy

Full Screen

...188 @slash.parametrize('param', [1, 2, 3])189 def fixture1(param): # pylint: disable=unused-argument190 pass191 fixtureobj = store.get_fixture_by_id(fixture1.__slash_fixture__.id)192 [(_, param_fixtureobj)] = iter_parametrization_fixtures(fixture1)193 with pytest.raises(UnresolvedFixtureStore):194 store.get_all_needed_fixture_ids(fixtureobj)195 store.resolve()196 needed = set(store.get_all_needed_fixture_ids(param_fixtureobj))197 assert len(needed) == 1198 assert needed == set([param_fixtureobj.info.id])199def test_fixture_store_iter_parametrization_variations_missing_fixtures(store):200 def test_func(needed_fixture):201 pass202 with pytest.raises(UnknownFixtures):203 list(store.iter_parametrization_variations(funcs=[test_func]))204def test_fixture_store_iter_parametrization_variations_unresolved(store):205 @store.add_fixture206 @slash.fixture...

Full Screen

Full Screen

parameters.py

Source:parameters.py Github

copy

Full Screen

...21 @wraps(func, preserve=['__slash_fixture__'])22 def new_func(*args, **kwargs):23 # for better debugging. _current_variation gets set to None on context exit24 variation = ctx.session.variations.get_current_variation()25 for name, param in params.iter_parametrization_fixtures():26 value = variation.get_param_value(param)27 if name not in kwargs:28 kwargs[name] = value29 return func(*args, **kwargs)30 setattr(new_func, _PARAM_INFO_ATTR_NAME, params)31 returned = new_func32 else:33 returned = func34 params.add_options(parameter_name, values)35 return returned36 return decorator37def iterate(**kwargs):38 def decorator(func):39 for name, options in kwargs.items():40 func = parametrize(name, options)(func)41 return func42 return decorator43def toggle(param_name):44 """A shortcut for :func:`slash.parametrize(param_name, [True, False]) <slash.parametrize>`45 .. note:: Also available for import as slash.parameters.toggle46 """47 return parametrize(param_name, (True, False))48@contextmanager49def bound_parametrizations_context(variation, fixture_store, fixture_namespace):50 assert ctx.session.variations.get_current_variation() is None51 ctx.session.variations.set_current_variation(variation)52 try:53 fixture_store.activate_autouse_fixtures_in_namespace(fixture_namespace)54 yield55 finally:56 ctx.session.variations.set_current_variation(None)57def iter_parametrization_fixtures(func):58 if isinstance(func, FixtureBase):59 func = func.fixture_func60 param_info = getattr(func, _PARAM_INFO_ATTR_NAME, None)61 if param_info is None:62 return []63 return param_info.iter_parametrization_fixtures()64class ParameterizationInfo(object):65 def __init__(self, func):66 super(ParameterizationInfo, self).__init__()67 self._argument_names = get_argument_names(func)68 self._argument_name_set = frozenset(self._argument_names)69 self._params = {}70 self._extra_params = {}71 self.path = '{}:{}'.format(func.__module__, func.__name__)72 def add_options(self, param_name, values):73 if param_name in self._params:74 raise ParameterException('{!r} already parametrized for {}'.format(75 param_name, self.path))76 values = list(values)77 if not isinstance(param_name, (list, tuple)):78 names = (param_name,)79 else:80 names = param_name81 values = _normalize_values(values, num_params=len(names))82 p = Parametrization(values=values, path='{}.{}'.format(self.path, param_name))83 for index, name in enumerate(names):84 if name in self._argument_name_set:85 params_dict = self._params86 else:87 params_dict = self._extra_params88 if len(names) > 1:89 params_dict[name] = p.as_transform(operator.itemgetter(index))90 else:91 params_dict[name] = p92 def iter_parametrization_fixtures(self):93 for name in self._argument_names:94 values = self._params.get(name)95 if values is not None:96 yield name, values97 for name, values in self._extra_params.items():98 yield name, values99def _id(obj):100 return obj101class Parametrization(FixtureBase):102 def __init__(self, path, values, info=None, transform=_id):103 super(Parametrization, self).__init__()104 self.path = path105 self.values = values106 if info is None:...

Full Screen

Full Screen

variation_factory.py

Source:variation_factory.py Github

copy

Full Screen

...33 if nofixtures.is_marked(func):34 return35 args = get_arguments(func)36 parametrizations = {}37 for name, param in iter_parametrization_fixtures(func):38 # make sure the parametrization is in the store39 self._store.ensure_known_parametrization(param)40 parametrizations[name] = param41 self._needed_fixtures.append(param)42 for argument in args:43 fixture = parametrizations.get(argument.name, None)44 if fixture is None:45 try:46 fixture = self._store.get_fixture_by_argument(argument)47 except FixtureException as e:48 raise type(e)('Loading {0.__code__.co_filename}:{0.__name__}: {1}'.format(func, e))49 self._needed_fixtures.append(fixture)50 arg_name = argument.name51 if namespace is not None:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful