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

Method parse

src/pytest_bdd/parser.py:481–506  ·  view source on GitHub ↗

Parse the feature file and return a Feature object with its backgrounds, rules, and scenarios.

(self)

Source from the content-addressed store, hash-verified

479 return get_gherkin_document(self.abs_filename, self.encoding)
480
481 def parse(self) -> Feature:
482 """Parse the feature file and return a Feature object with its backgrounds, rules, and scenarios."""
483 gherkin_doc: GherkinDocument = self._parse_feature_file()
484 feature_data: GherkinFeature = gherkin_doc.feature
485 feature = Feature(
486 scenarios=OrderedDict(),
487 keyword=feature_data.keyword,
488 filename=self.abs_filename,
489 rel_filename=self.rel_filename,
490 name=feature_data.name,
491 tags=get_tag_names(feature_data.tags),
492 background=None,
493 line_number=feature_data.location.line,
494 description=textwrap.dedent(feature_data.description),
495 language=feature_data.language,
496 )
497
498 for child in feature_data.children:
499 if child.background:
500 feature.background = self.parse_background(child.background)
501 elif child.rule:
502 self._parse_and_add_rule(child.rule, feature)
503 elif child.scenario:
504 self._parse_and_add_scenario(child.scenario, feature)
505
506 return feature
507
508 def _parse_and_add_rule(self, rule_data: GherkinRule, feature: Feature) -> None:
509 """Parse a rule, including its background and scenarios, and add to the feature."""

Callers 4

get_featureFunction · 0.80
parse_argumentsMethod · 0.80
is_matchingMethod · 0.80
get_gherkin_documentFunction · 0.80

Calls 6

_parse_feature_fileMethod · 0.95
parse_backgroundMethod · 0.95
_parse_and_add_ruleMethod · 0.95
get_tag_namesFunction · 0.85
FeatureClass · 0.70

Tested by

no test coverage detected