pytest-bdd icon indicating copy to clipboard operation
pytest-bdd copied to clipboard

feat: use scenarios() shortcut in code generation template

Open toroleapinc opened this issue 9 months ago • 1 comments

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 scenarios instead of scenario
  • 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')

toroleapinc avatar Mar 03 '26 06:03 toroleapinc

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.

toroleapinc avatar Apr 27 '26 04:04 toroleapinc

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.

codecov[bot] avatar Jul 03 '26 05:07 codecov[bot]

@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?

youtux avatar Jul 05 '26 15:07 youtux

Sorry that's my bad, do you want me to revert ?

Pierre-Sassoulas avatar Jul 05 '26 17:07 Pierre-Sassoulas

Yes please, let's then address my comments and then we can ship it

youtux avatar Jul 05 '26 17:07 youtux

I added a test in the new MR regarding idempotency.

Pierre-Sassoulas avatar Jul 05 '26 18:07 Pierre-Sassoulas