feat: use scenarios() shortcut in code generation template
Summary
Update the code generation template to use the scenarios() shortcut instead of individual @scenario() decorators.
Closes #535
Changes
Modified src/pytest_bdd/templates/test.py.mak to:
- Import
scenariosinstead ofscenario - Generate
scenarios('feature_file.feature')calls instead of individual@scenario(...)decorated test functions - Automatically deduplicate feature file paths
Before
from pytest_bdd import given, scenario, then, when
@scenario('features/login.feature', 'Successful login')
def test_successful_login(): ...
@scenario('features/login.feature', 'Failed login')
def test_failed_login(): ...
After
from pytest_bdd import given, scenarios, then, when
scenarios('features/login.feature')
Pushed ed581b5 — updated the expected output strings in tests/scripts/test_generate.py (test_generate, test_generate_with_quotes, test_unicode_characters) to match the new scenarios() codegen output. Verified locally on Python 3.13: the 3 codegen tests pass, and the only remaining test failure I see (test_step_outside_scenario_or_background_error) reproduces on upstream/master too, so it's pre-existing and not from this PR.
Looks like the CI run is currently blocked on action_required (workflow approval for the fork). Could a maintainer approve it when you get a chance? Thanks.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 96.10%. Comparing base (9454b38) to head (f0e0299).
:warning: Report is 1 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #796 +/- ##
=======================================
Coverage 96.10% 96.10%
=======================================
Files 55 55
Lines 2390 2390
Branches 136 136
=======================================
Hits 2297 2297
Misses 56 56
Partials 37 37
:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@Pierre-Sassoulas why did you merge this before my comment was addressed?
Also, with this change do we preserve idempotency, in case the autogen script is invoked twice?
Sorry that's my bad, do you want me to revert ?
Yes please, let's then address my comments and then we can ship it
I added a test in the new MR regarding idempotency.