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

Test that step args and example params with the same name do not redefine each other #745

Merged
merged 7 commits into from
Dec 2, 2024
Merged
Changes from 5 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
55 changes: 55 additions & 0 deletions tests/feature/test_outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,58 @@ def _(site):
result = pytester.runpytest("-s")
result.assert_outcomes(passed=1)
assert collect_dumped_objects(result) == ["https://my-site.com"]


def test_variable_reuse(pytester):
"""
Test example parameter name and step arg do not redefine each other's value
if the same name is used for both in different steps.
"""

pytester.makefile(
".feature",
outline=textwrap.dedent(
"""\
Feature: Example parameters reuse
Scenario Outline: Check for example parameter re-use
Given I get <param>
When I set param to "other"
Then I check <param>

Examples:
| param |
| value |

"""
),
)

pytester.makepyfile(
textwrap.dedent(
"""\
from pytest_bdd import given, when, then, parsers, scenarios
from pytest_bdd.utils import dump_obj

scenarios('outline.feature')


@given(parsers.parse('I get {param}'))
def _(param):
dump_obj(("param1", param))


@when(parsers.re('I set param to "(?P<param>.+)"'))
def _(param):
dump_obj(("param2", param))
jsa34 marked this conversation as resolved.
Show resolved Hide resolved


@then(parsers.parse('I check {param}'))
def _(param):
dump_obj(("param3", param))

"""
)
)
result = pytester.runpytest("-s")
result.assert_outcomes(passed=1)
assert collect_dumped_objects(result) == [("param1", "value"), ("param2", "other"), ("param3", "value")]
Loading