Skip to content

Commit 86a956e

Browse files
authored
Merge pull request #745 from pytest-dev/test-177
2 parents 6a2b2fb + 633ee28 commit 86a956e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/feature/test_outline.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,58 @@ def _(site):
320320
result = pytester.runpytest("-s")
321321
result.assert_outcomes(passed=1)
322322
assert collect_dumped_objects(result) == ["https://my-site.com"]
323+
324+
325+
def test_variable_reuse(pytester):
326+
"""
327+
Test example parameter name and step arg do not redefine each other's value
328+
if the same name is used for both in different steps.
329+
"""
330+
331+
pytester.makefile(
332+
".feature",
333+
outline=textwrap.dedent(
334+
"""\
335+
Feature: Example parameters reuse
336+
Scenario Outline: Check for example parameter re-use
337+
Given the param is initially set from the example table as <param>
338+
When a step arg of the same name is set to "other"
339+
Then the param is still set from the example table as <param>
340+
341+
Examples:
342+
| param |
343+
| value |
344+
345+
"""
346+
),
347+
)
348+
349+
pytester.makepyfile(
350+
textwrap.dedent(
351+
"""\
352+
from pytest_bdd import given, when, then, parsers, scenarios
353+
from pytest_bdd.utils import dump_obj
354+
355+
scenarios('outline.feature')
356+
357+
358+
@given(parsers.parse('the param is initially set from the example table as {param}'))
359+
def _(param):
360+
dump_obj(("param1", param))
361+
362+
363+
@when(parsers.re('a step arg of the same name is set to "(?P<param>.+)"'))
364+
def _(param):
365+
dump_obj(("param2", param))
366+
367+
368+
@then(parsers.parse('the param is still set from the example table as {param}'))
369+
def _(param):
370+
dump_obj(("param3", param))
371+
372+
"""
373+
)
374+
)
375+
result = pytester.runpytest("-s")
376+
result.assert_outcomes(passed=1)
377+
assert collect_dumped_objects(result) == [("param1", "value"), ("param2", "other"), ("param3", "value")]

0 commit comments

Comments
 (0)