Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore </> in step parameter values #465

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pytest_bdd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions tests/feature/test_steps.py
Original file line number Diff line number Diff line change
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