Best Python code snippet using tavern
file.py
Source:file.py  
...172        # 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            ]230            if parametrize_marks:231                yield from _get_parametrized_items(232                    self, test_spec, parametrize_marks, pytest_marks233                )234                # Only yield the parametrized ones...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
