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 1/3] 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 _(): From 750a007b63ab688196965a63b2e9c4420f4c3a15 Mon Sep 17 00:00:00 2001 From: Eddie Liang Date: Thu, 12 Mar 2026 13:55:38 -0400 Subject: [PATCH 2/3] Use features var instead of scenarios for extracting feature paths --- src/pytest_bdd/templates/test.py.mak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pytest_bdd/templates/test.py.mak b/src/pytest_bdd/templates/test.py.mak index f351b039a..d48b52205 100644 --- a/src/pytest_bdd/templates/test.py.mak +++ b/src/pytest_bdd/templates/test.py.mak @@ -1,5 +1,5 @@ <% - feature_paths = sorted(set(s.feature.rel_filename for s in scenarios)) + feature_paths = sorted(set(f.rel_filename for f in features)) %>\ % if features: """${ features[0].name or features[0].rel_filename } feature tests.""" From ed581b5f595932ccffcd011325827adabaed5723 Mon Sep 17 00:00:00 2001 From: Eddie Liang Date: Mon, 27 Apr 2026 00:41:17 -0400 Subject: [PATCH 3/3] test: update codegen test expectations for scenarios() shortcut The template now emits a single scenarios('foo.feature') call instead of one @scenario(...) decorator per scenario, so the expected output strings in test_generate, test_generate_with_quotes, and test_unicode_characters need to match. --- tests/scripts/test_generate.py | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/tests/scripts/test_generate.py b/tests/scripts/test_generate.py index e194076d1..098099dd4 100644 --- a/tests/scripts/test_generate.py +++ b/tests/scripts/test_generate.py @@ -42,15 +42,12 @@ def test_generate(pytester, monkeypatch, capsys): from pytest_bdd import ( given, - scenario, + scenarios, then, when, ) - - @scenario('scripts/generate.feature', 'Given and when using the same fixture should not evaluate it twice') - def test_given_and_when_using_the_same_fixture_should_not_evaluate_it_twice(): - """Given and when using the same fixture should not evaluate it twice.""" + scenarios('scripts/generate.feature') @given('1 have a fixture (appends 1 to a list) in reuse syntax') @@ -108,15 +105,12 @@ def test_generate_with_quotes(pytester): from pytest_bdd import ( given, - scenario, + scenarios, then, when, ) - - @scenario('generate_with_quotes.feature', 'A step definition with quotes should be escaped as needed') - def test_a_step_definition_with_quotes_should_be_escaped_as_needed(): - """A step definition with quotes should be escaped as needed.""" + scenarios('generate_with_quotes.feature') @given('I have a fixture with "double" quotes') @@ -184,15 +178,12 @@ def test_unicode_characters(pytester, monkeypatch): from pytest_bdd import ( given, - scenario, + scenarios, then, when, ) - - @scenario('unicode_characters.feature', 'Calculating the circumference of a circle') - def test_calculating_the_circumference_of_a_circle(): - """Calculating the circumference of a circle.""" + scenarios('unicode_characters.feature') @given('We have a circle')