From cd471dbe660a02a576ef3a9aa1748b7783a58638 Mon Sep 17 00:00:00 2001 From: yunusyun Date: Fri, 8 Nov 2024 17:39:33 +0800 Subject: [PATCH 1/2] fix: defalut value not covered by parameters passed through feature file --- src/pytest_bdd/scenario.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pytest_bdd/scenario.py b/src/pytest_bdd/scenario.py index 08a53c3c..f228332f 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 From 7393c8f14a7b74ad8fbd0602a8371923269899e8 Mon Sep 17 00:00:00 2001 From: yunusyun Date: Fri, 15 Nov 2024 17:17:58 +0800 Subject: [PATCH 2/2] test: add test case for scenario --- tests/feature/test_scenario.py | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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)