From fe4e88308557ca5853dba9572f14ab3a6181aefc Mon Sep 17 00:00:00 2001 From: edvatar <88481784+toroleapinc@users.noreply.github.com> Date: Tue, 3 Mar 2026 01:24:12 -0500 Subject: [PATCH] feat: use scenarios() shortcut in code generation template Replace individual @scenario() decorators with the scenarios() shortcut function in the code generation template. This produces cleaner, more concise generated test code. Before: @scenario('feature.feature', 'Scenario 1') def test_scenario_1(): ... @scenario('feature.feature', 'Scenario 2') def test_scenario_2(): ... After: scenarios('feature.feature') Closes #535 Signed-off-by: edvatar <88481784+toroleapinc@users.noreply.github.com> --- src/pytest_bdd/templates/test.py.mak | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pytest_bdd/templates/test.py.mak b/src/pytest_bdd/templates/test.py.mak index 9f7901539..f351b039a 100644 --- a/src/pytest_bdd/templates/test.py.mak +++ b/src/pytest_bdd/templates/test.py.mak @@ -1,22 +1,22 @@ +<% + feature_paths = sorted(set(s.feature.rel_filename for s in scenarios)) +%>\ % if features: """${ features[0].name or features[0].rel_filename } feature tests.""" from pytest_bdd import ( given, - scenario, + scenarios, then, when, ) - -% endif -% for scenario in sorted(scenarios, key=lambda scenario: scenario.name): -@scenario('${scenario.feature.rel_filename}', ${ make_string_literal(scenario.name)}) -def test_${ make_python_name(scenario.name)}(): - ${make_python_docstring(scenario.name)} +% for feature_path in feature_paths: +scenarios('${feature_path}') +% endfor -% endfor +% endif % for step in steps: @${step.type}(${ make_string_literal(step.name)}) def _():