Skip to content

feat: use scenarios() shortcut in code generation template#796

Open
toroleapinc wants to merge 1 commit intopytest-dev:masterfrom
toroleapinc:feat/issue-535-use-scenarios-shortcut
Open

feat: use scenarios() shortcut in code generation template#796
toroleapinc wants to merge 1 commit intopytest-dev:masterfrom
toroleapinc:feat/issue-535-use-scenarios-shortcut

Conversation

@toroleapinc
Copy link

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')

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 pytest-dev#535

Signed-off-by: edvatar <88481784+toroleapinc@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scenario generation should use scenarios shortcut

1 participant