diff --git a/pytest_bdd/parser.py b/pytest_bdd/parser.py index 8cbfbb14..81ddec38 100644 --- a/pytest_bdd/parser.py +++ b/pytest_bdd/parser.py @@ -357,8 +357,16 @@ def params(self): return tuple(frozenset(STEP_PARAM_RE.findall(self.name))) def render(self, context: typing.Mapping[str, typing.Any]): + example_params = set() + if self.scenario: + example_params |= set(self.scenario.feature.examples.example_params) + if hasattr(self.scenario, "examples"): + example_params |= set(self.scenario.examples.example_params) + def replacer(m: typing.Match): varname = m.group(1) + if varname not in example_params: + return m.group(0) return str(context[varname]) return STEP_PARAM_RE.sub(replacer, self.name) diff --git a/tests/feature/test_steps.py b/tests/feature/test_steps.py index 63ed1498..4c9a7fd8 100644 --- a/tests/feature/test_steps.py +++ b/tests/feature/test_steps.py @@ -11,12 +11,12 @@ def test_steps(testdir): are not mandatory in some cases. Scenario: Executed step by step - Given I have a foo fixture with value "foo" + Given I have a foo fixture with value "

foo

" And there is a list When I append 1 to the list And I append 2 to the list And I append 3 to the list - Then foo should have value "foo" + Then foo should have value "

foo

" But the list should be [1, 2, 3] """ ), @@ -25,15 +25,15 @@ def test_steps(testdir): testdir.makepyfile( textwrap.dedent( """\ - from pytest_bdd import given, when, then, scenario + from pytest_bdd import given, when, then, scenario, parsers @scenario("steps.feature", "Executed step by step") def test_steps(): pass - @given('I have a foo fixture with value "foo"', target_fixture="foo") - def foo(): - return "foo" + @given(parsers.parse('I have a foo fixture with value "{value}"'), target_fixture="foo") + def foo(value): + return value @given("there is a list", target_fixture="results") @@ -56,9 +56,9 @@ def append_3(results): results.append(3) - @then('foo should have value "foo"') - def foo_is_foo(foo): - assert foo == "foo" + @then(parsers.parse('foo should have value "{value}"')) + def foo_is_foo(foo, value): + assert foo == value @then("the list should be [1, 2, 3]")