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

Method parse_steps

src/pytest_bdd/parser.py:380–417  ·  view source on GitHub ↗

Parse a list of step data into Step objects. Args: steps_data (List[dict]): The list of step data. Returns: List[Step]: A list of Step objects.

(self, steps_data: list[GherkinStep])

Source from the content-addressed store, hash-verified

378 self.encoding = encoding
379
380 def parse_steps(self, steps_data: list[GherkinStep]) -> list[Step]:
381 """Parse a list of step data into Step objects.
382
383 Args:
384 steps_data (List[dict]): The list of step data.
385
386 Returns:
387 List[Step]: A list of Step objects.
388 """
389
390 if not steps_data:
391 return []
392
393 first_step = steps_data[0]
394 if first_step.keyword_type not in STEP_TYPE_BY_PARSER_KEYWORD:
395 raise StepError(
396 message=f"First step in a scenario or background must start with 'Given', 'When' or 'Then', but got {first_step.keyword}.",
397 line=first_step.location.line,
398 line_content=first_step.text,
399 filename=self.abs_filename,
400 )
401
402 steps = []
403 current_type = STEP_TYPE_BY_PARSER_KEYWORD[first_step.keyword_type]
404 for step in steps_data:
405 current_type = STEP_TYPE_BY_PARSER_KEYWORD.get(step.keyword_type, current_type)
406 steps.append(
407 Step(
408 name=step.text,
409 type=current_type,
410 indent=step.location.column - 1,
411 line_number=step.location.line,
412 keyword=step.keyword.title(),
413 datatable=step.datatable,
414 docstring=step.docstring.content if step.docstring else None,
415 )
416 )
417 return steps
418
419 def parse_scenario(
420 self, scenario_data: GherkinScenario, feature: Feature, rule: Rule | None = None

Callers 2

parse_scenarioMethod · 0.95
parse_backgroundMethod · 0.95

Calls 2

StepErrorClass · 0.85
StepClass · 0.70

Tested by

no test coverage detected