diff --git a/features/steps/acms_budget_enforcement_steps.py b/features/steps/acms_budget_enforcement_steps.py index 383cb2906..8a491b626 100644 --- a/features/steps/acms_budget_enforcement_steps.py +++ b/features/steps/acms_budget_enforcement_steps.py @@ -23,19 +23,21 @@ def step_create_budget_enforcer_with_max_file_size(context, size: int) -> None: def step_create_budget_enforcer_with_max_total_size(context, size: int) -> None: """Update the budget enforcer's max_total_size. - Reconstructs a fresh BudgetEnforcer preserving the already-set - max_file_size so both Background steps together fully configure - constraints for each new scenario. + Always reconstructs a fresh BudgetEnforcer unconditionally — + the Background runs before each scenario and must reset state to + prevent leakage between scenarios within the same feature file. + The previously-set max_file_size from step_one determines the new + enforcer's constraint since both Background steps run sequentially. """ + # Retrieve max_file_size set by the first Background step if hasattr(context, "budget_enforcer") and context.budget_enforcer is not None: - context.budget_enforcer = BudgetEnforcer( - max_file_size=context.budget_enforcer.max_file_size, - max_total_size=size, - ) + _max_file_size = context.budget_enforcer.max_file_size else: - context.budget_enforcer = BudgetEnforcer( - max_file_size=10000, max_total_size=size - ) + _max_file_size = 10000 # Default fallback + context.budget_enforcer = BudgetEnforcer( + max_file_size=_max_file_size, + max_total_size=size, + ) @when("I add a file of {size:d} bytes to the context")