MCPcopy Create free account
hub / github.com/pytest-dev/pytest-bdd / parse_scenario

Method parse_scenario

src/pytest_bdd/parser.py:419–462  ·  view source on GitHub ↗

Parse a scenario data dictionary into a ScenarioTemplate object. Args: scenario_data (dict): The dictionary containing scenario data. feature (Feature): The feature to which this scenario belongs. rule (Optional[Rule]): The rule to which this scenario may

(
        self, scenario_data: GherkinScenario, feature: Feature, rule: Rule | None = None
    )

Source from the content-addressed store, hash-verified

417 return steps
418
419 def parse_scenario(
420 self, scenario_data: GherkinScenario, feature: Feature, rule: Rule | None = None
421 ) -> ScenarioTemplate:
422 """Parse a scenario data dictionary into a ScenarioTemplate object.
423
424 Args:
425 scenario_data (dict): The dictionary containing scenario data.
426 feature (Feature): The feature to which this scenario belongs.
427 rule (Optional[Rule]): The rule to which this scenario may belong. (None = no rule)
428
429 Returns:
430 ScenarioTemplate: A ScenarioTemplate object representing the parsed scenario.
431 """
432 templated = bool(scenario_data.examples)
433 scenario = ScenarioTemplate(
434 feature=feature,
435 keyword=scenario_data.keyword,
436 name=scenario_data.name,
437 line_number=scenario_data.location.line,
438 templated=templated,
439 tags=get_tag_names(scenario_data.tags),
440 description=textwrap.dedent(scenario_data.description),
441 rule=rule,
442 )
443 for step in self.parse_steps(scenario_data.steps):
444 scenario.add_step(step)
445
446 # Loop over multiple example tables if they exist
447 for example_data in scenario_data.examples:
448 examples = Examples(
449 line_number=example_data.location.line,
450 name=example_data.name,
451 tags=get_tag_names(example_data.tags),
452 )
453 if example_data.table_header is not None:
454 param_names = [cell.value for cell in example_data.table_header.cells]
455 examples.set_param_names(param_names)
456 if example_data.table_body is not None:
457 for row in example_data.table_body:
458 values = [cell.value or "" for cell in row.cells]
459 examples.add_example(values)
460 scenario.examples.append(examples)
461
462 return scenario
463
464 def parse_background(self, background_data: GherkinBackground) -> Background:
465 background = Background(

Callers 2

Calls 7

parse_stepsMethod · 0.95
add_stepMethod · 0.95
set_param_namesMethod · 0.95
add_exampleMethod · 0.95
ScenarioTemplateClass · 0.85
get_tag_namesFunction · 0.85
ExamplesClass · 0.85

Tested by

no test coverage detected