Best Python code snippet using pytest-bdd_python
reporting.py
Source:reporting.py  
...74        :return: Last or current step report.75        :rtype: pytest_bdd.reporting.StepReport76        """77        return self.step_reports[-1]78    def add_step_report(self, step_report):79        """Add new step report.80        :param step_report: New current step report.81        :type step_report: pytest_bdd.reporting.StepReport82        """83        self.step_reports.append(step_report)84    def serialize(self):85        """Serialize scenario excecution report in order to transfer reportin from nodes in the distributed mode.86        :return: Serialized report.87        :rtype: dict88        """89        scenario = self.scenario90        feature = scenario.feature91        params = sum(scenario.get_params(builtin=True), []) if scenario.examples else None92        return {93            "steps": [step_report.serialize() for step_report in self.step_reports],94            "name": scenario.name,95            "line_number": scenario.line_number,96            "tags": sorted(scenario.tags),97            "feature": {98                "name": feature.name,99                "filename": feature.filename,100                "rel_filename": feature.rel_filename,101                "line_number": feature.line_number,102                "description": feature.description,103                "tags": sorted(feature.tags),104            },105            "examples": [106                {107                    "name": scenario.examples.name,108                    "line_number": scenario.examples.line_number,109                    "rows": params,110                    "row_index": self.param_index,111                }112            ]113            if scenario.examples114            else [],115            "example_kwargs": self.example_kwargs,116        }117    def fail(self):118        """Stop collecting information and finalize the report as failed."""119        self.current_step_report.finalize(failed=True)120        remaining_steps = self.scenario.steps[len(self.step_reports) :]121        # Fail the rest of the steps and make reports.122        for step in remaining_steps:123            report = StepReport(step=step)124            report.finalize(failed=True)125            self.add_step_report(report)126def runtest_makereport(item, call, rep):127    """Store item in the report object."""128    try:129        scenario_report = item.__scenario_report__130    except AttributeError:131        pass132    else:133        rep.scenario = scenario_report.serialize()134        rep.item = {"name": item.name}135def before_scenario(request, feature, scenario):136    """Create scenario report for the item."""137    request.node.__scenario_report__ = ScenarioReport(scenario=scenario, node=request.node)138def step_error(request, feature, scenario, step, step_func, step_func_args, exception):139    """Finalize the step report as failed."""140    request.node.__scenario_report__.fail()141def before_step(request, feature, scenario, step, step_func):142    """Store step start time."""143    request.node.__scenario_report__.add_step_report(StepReport(step=step))144def after_step(request, feature, scenario, step, step_func, step_func_args):145    """Finalize the step report as successful."""...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!!
