Skip to content

Commit

Permalink
Ignore </> in step parameter values
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikuncar committed Dec 15, 2021
1 parent 2026dec commit 9cc09f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pytest_bdd/parser.py
Expand Up @@ -357,8 +357,12 @@ def params(self):
return tuple(frozenset(STEP_PARAM_RE.findall(self.name)))

def render(self, context: typing.Mapping[str, typing.Any]):
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)
Expand Down
18 changes: 9 additions & 9 deletions tests/feature/test_steps.py
Expand Up @@ -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 "<h1>foo</h1>"
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 "<h1>foo</h1>"
But the list should be [1, 2, 3]
"""
),
Expand All @@ -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")
Expand All @@ -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]")
Expand Down

0 comments on commit 9cc09f7

Please sign in to comment.