How to use yamlitem_from_parent method in tavern

Best Python code snippet using tavern

file.py

Source:file.py Github

copy

Full Screen

...156 "variables": variables,157 }158 )159 # And create the new item160 item_new = YamlItem.yamlitem_from_parent(161 spec_new["test_name"], parent, spec_new, parent.fspath162 )163 item_new.add_markers(pytest_marks)164 yield item_new165class YamlFile(pytest.File):166 """Custom `File` class that loads each test block as a different test"""167 # pylint:disable=no-member168 def __init__(self, *args, **kwargs):169 super().__init__(*args, **kwargs)170 # This (and the FakeObj below) are to make pytest-pspec not error out.171 # The 'docstring' for this is the filename, the 'docstring' for each172 # individual test is the actual test name.173 class FakeObj(object):174 __doc__ = self.fspath.strpath175 self.obj = FakeObj176 def _get_test_fmt_vars(self, test_spec):177 """Get any format variables that can be inferred for the test at this point178 Args:179 test_spec (dict): Test specification, possibly with included config files180 Returns:181 dict: available format variables182 """183 # Get included variables so we can do things like:184 # skipif: {my_integer} > 2185 # skipif: 'https' in '{hostname}'186 # skipif: '{hostname}'.contains('ignoreme')187 fmt_vars = {}188 global_cfg = load_global_cfg(self.config)189 fmt_vars.update(**global_cfg.get("variables", {}))190 included = test_spec.get("includes", [])191 for i in included:192 fmt_vars.update(**i.get("variables", {}))193 if self.session.config.option.collectonly:194 tavern_box = Box(default_box=True)195 else:196 # Needed if something in a config file uses tavern.env_vars197 tavern_box = get_tavern_box()198 try:199 fmt_vars = _format_without_inner(fmt_vars, tavern_box)200 except exceptions.MissingFormatError as e:201 # eg, if we have {tavern.env_vars.DOESNT_EXIST}202 msg = "Tried to use tavern format variable that did not exist"203 raise exceptions.MissingFormatError(msg) from e204 tavern_box.merge_update(**fmt_vars)205 return tavern_box206 def _generate_items(self, test_spec):207 """Modify or generate tests based on test spec208 If there are any 'parametrize' marks, this will generate extra tests209 based on the values210 Args:211 test_spec (dict): Test specification212 Yields:213 YamlItem: Tavern YAML test214 """215 item = YamlItem.yamlitem_from_parent(216 test_spec["test_name"], self, test_spec, self.fspath217 )218 original_marks = test_spec.get("marks", [])219 if original_marks:220 fmt_vars = self._get_test_fmt_vars(test_spec)221 pytest_marks, formatted_marks = _format_test_marks(222 original_marks, fmt_vars, test_spec["test_name"]223 )224 # Do this after we've added all the other marks so doing225 # things like selecting on mark names still works even226 # after parametrization227 parametrize_marks = [228 i for i in formatted_marks if isinstance(i, dict) and "parametrize" in i229 ]...

Full Screen

Full Screen

item.py

Source:item.py Github

copy

Full Screen

...25 self.path = path26 self.spec = spec27 self.global_cfg = {}28 @classmethod29 def yamlitem_from_parent(cls, name, parent, spec, path):30 return cls.from_parent(parent, name=name, spec=spec, path=path)31 def initialise_fixture_attrs(self):32 # pylint: disable=protected-access,attribute-defined-outside-init33 self.funcargs = {}34 # _get_direct_parametrize_args checks parametrize arguments in Python35 # functions, but we don't care about that in Tavern.36 self.session._fixturemanager._get_direct_parametrize_args = lambda _: []37 fixtureinfo = self.session._fixturemanager.getfixtureinfo(38 self, self.obj, type(self), funcargs=False39 )40 self._fixtureinfo = fixtureinfo41 self.fixturenames = fixtureinfo.names_closure42 self._request = pytest.FixtureRequest(self, _ispytest=True)43 # Hack to stop issue with pytest-rerunfailures...

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 tavern 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