diff --git a/src/pytest_bdd/scenario.py b/src/pytest_bdd/scenario.py index ac8844c5..2058078f 100644 --- a/src/pytest_bdd/scenario.py +++ b/src/pytest_bdd/scenario.py @@ -210,7 +210,9 @@ def _execute_step_function( if step.docstring is not None: kwargs["docstring"] = step.docstring - kwargs = {arg: kwargs[arg] if arg in kwargs else request.getfixturevalue(arg) for arg in args} + for arg in args: + if arg not in kwargs: + kwargs[arg] = request.getfixturevalue(arg) kw["step_func_args"] = kwargs diff --git a/tests/feature/test_scenario.py b/tests/feature/test_scenario.py index b8664e21..bf7c46f1 100644 --- a/tests/feature/test_scenario.py +++ b/tests/feature/test_scenario.py @@ -279,3 +279,46 @@ def _(): ("given", "che uso uno step con ", "esempio 2"), ("then", "va tutto bene"), ] + + +def test_default_value_in_not_parsed(pytester): + """Test that angular brackets are not parsed for "Scenario"s. + + (They should be parsed only when used in "Scenario Outline") + + """ + pytester.makefile( + ".feature", + simple=""" + Feature: Simple feature + Scenario: Simple scenario + Given a user with username + Then check username defaultuser + + Scenario Outline: Outlined scenario + Given a user with username + Then check username + + Examples: + | username | + | user1 | + """, + ) + pytester.makepyfile( + """ + from pytest_bdd import scenarios, given, then, parsers + + scenarios("simple.feature") + + @given('a user with username', target_fixture="user") + @given(parsers.parse('a user with username {username}'), target_fixture="user") + def create_user(username="defaultuser"): + return username + + @then(parsers.parse("check username {username}")) + def _(user, username): + assert user == username + """ + ) + result = pytester.runpytest() + result.assert_outcomes(passed=2)