@@ -169,13 +169,7 @@ def steps(self) -> list[Step]:
169
169
Returns:
170
170
List[Step]: A list of steps, including any background steps from the feature.
171
171
"""
172
- steps = []
173
- # Add all background steps
174
- steps .extend (self .all_background_steps )
175
- # Add the scenario's own steps
176
- steps .extend (self ._steps )
177
-
178
- return steps
172
+ return self .all_background_steps + self ._steps
179
173
180
174
def render (self , context : Mapping [str , Any ]) -> Scenario :
181
175
"""Render the scenario with the given context.
@@ -328,12 +322,10 @@ class Background:
328
322
"""Represents the background steps for a feature.
329
323
330
324
Attributes:
331
- parent (Feature | Rule): The feature or rule to which this background belongs.
332
325
line_number (int): The line number where the background starts in the file.
333
326
steps (List[Step]): The list of steps in the background.
334
327
"""
335
328
336
- parent : Feature | Rule
337
329
line_number : int
338
330
steps : list [Step ] = field (init = False , default_factory = list )
339
331
@@ -455,9 +447,8 @@ def parse_scenario(
455
447
456
448
return scenario
457
449
458
- def parse_background (self , background_data : GherkinBackground , parent : Feature | Rule ) -> Background :
450
+ def parse_background (self , background_data : GherkinBackground ) -> Background :
459
451
background = Background (
460
- parent = parent ,
461
452
line_number = background_data .location .line ,
462
453
)
463
454
background .steps = self .parse_steps (background_data .steps )
@@ -492,7 +483,7 @@ def parse(self) -> Feature:
492
483
493
484
for child in feature_data .children :
494
485
if child .background :
495
- feature .background = self .parse_background (child .background , feature )
486
+ feature .background = self .parse_background (child .background )
496
487
elif child .rule :
497
488
self ._parse_and_add_rule (child .rule , feature )
498
489
elif child .scenario :
@@ -511,7 +502,7 @@ def _parse_and_add_rule(self, rule_data: GherkinRule, feature: Feature) -> None:
511
502
)
512
503
513
504
# Add background if present within the rule
514
- background = self ._extract_rule_background (rule_data , rule )
505
+ background = self ._extract_rule_background (rule_data )
515
506
if background :
516
507
rule .add_background (background )
517
508
@@ -520,11 +511,11 @@ def _parse_and_add_rule(self, rule_data: GherkinRule, feature: Feature) -> None:
520
511
scenario = self .parse_scenario (rule_scenario , feature , rule )
521
512
feature .scenarios [scenario .name ] = scenario
522
513
523
- def _extract_rule_background (self , rule_data : GherkinRule , rule : Rule ) -> Background | None :
514
+ def _extract_rule_background (self , rule_data : GherkinRule ) -> Background | None :
524
515
"""Extract the first background from rule children if it exists."""
525
516
for child in rule_data .children :
526
517
if child .background :
527
- return self .parse_background (child .background , rule )
518
+ return self .parse_background (child .background )
528
519
return None
529
520
530
521
@staticmethod
0 commit comments