Skip to content

Commit

Permalink
Response to feedback: remove add_background and use constructor; remo…
Browse files Browse the repository at this point in the history
…ve unnecessary sorting
  • Loading branch information
jsa34 committed Nov 13, 2024
1 parent dd145a2 commit 4017171
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/pytest_bdd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ class Rule:
tags: set[str]
background: Background | None = None

def add_background(self, background: Background) -> None:
self.background = background


@dataclass(eq=False)
class ScenarioTemplate:
Expand Down Expand Up @@ -492,19 +489,16 @@ def parse(self) -> Feature:

def _parse_and_add_rule(self, rule_data: GherkinRule, feature: Feature) -> None:
"""Parse a rule, including its background and scenarios, and add to the feature."""
background = self._extract_rule_background(rule_data)

rule = Rule(
keyword=rule_data.keyword,
name=rule_data.name,
description=rule_data.description,
tags=self.get_tag_names(rule_data.tags),
background=background,
)

# Add background if present within the rule
background = self._extract_rule_background(rule_data)
if background:
rule.add_background(background)

# Parse and add scenarios under the rule
for scenario in self._extract_rule_scenarios(rule_data, feature, rule):
feature.scenarios[scenario.name] = scenario

Expand Down
2 changes: 1 addition & 1 deletion src/pytest_bdd/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def serialize(self) -> dict[str, Any]:
"keyword": scenario.rule.keyword,
"name": scenario.rule.name,
"description": scenario.rule.description,
"tags": sorted(scenario.rule.tags),
"tags": scenario.rule.tags,
}

return serialized
Expand Down

0 comments on commit 4017171

Please sign in to comment.