Best Python code snippet using tavern
item.py
Source:item.py  
...91                        " be a list of fixture names)"92                    )93                    continue94            self.add_marker(pm)95    def _load_fixture_values(self):96        fixture_markers = self.iter_markers("usefixtures")97        values = {}98        for m in fixture_markers:99            if isinstance(m.args, (list, tuple)):100                mark_values = {f: self.funcargs[f] for f in m.args}101            elif isinstance(m.args, str):102                # Not sure if this can happen if validation is working103                # correctly, but it appears to be slightly broken so putting104                # this check here just in case105                mark_values = {m.args: self.funcargs[m.args]}106            else:107                raise exceptions.BadSchemaError(108                    (109                        "Can't handle 'usefixtures' spec of '{}'."110                        " There appears to be a bug in pykwalify so verification of"111                        " 'usefixtures' is broken - it should be a list of fixture"112                        " names"113                    ).format(m.args)114                )115            if any(mv in values for mv in mark_values):116                logger.warning("Overriding value for %s", mark_values)117            values.update(mark_values)118        # Use autouse fixtures as well119        for m in self.fixturenames:120            if m in values:121                logger.debug("%s already explicitly used", m)122                continue123            mark_values = {m: self.funcargs[m]}124            values.update(mark_values)125        return values126    def runtest(self):127        # Do a deep copy because this sometimes still retains things from previous tests(?)128        self.global_cfg = copy.deepcopy(load_global_cfg(self.config))129        self.global_cfg.setdefault("variables", {})130        load_plugins(self.global_cfg)131        self.global_cfg["tavern_internal"] = {"pytest_hook_caller": self.config.hook}132        # INTERNAL133        # NOTE - now that we can 'mark' tests, we could use pytest.mark.xfail134        # instead. This doesn't differentiate between an error in verification135        # and an error when running the test though.136        xfail = self.spec.get("_xfail", False)137        try:138            fixture_values = self._load_fixture_values()139            self.global_cfg["variables"].update(fixture_values)140            call_hook(141                self.global_cfg,142                "pytest_tavern_beta_before_every_test_run",143                test_dict=self.spec,144                variables=self.global_cfg["variables"],145            )146            verify_tests(self.spec)147            for stage in self.spec["stages"]:148                if not stage.get("name"):149                    if not stage.get("id"):150                        # Should never actually reach here, should be caught at schema check time151                        raise exceptions.BadSchemaError(152                            "One of name or ID must be specified"...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!!
