@@ -320,3 +320,63 @@ 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+ """Test example parameter reuse."""
327+
328+ pytester .makefile (
329+ ".feature" ,
330+ outline = textwrap .dedent (
331+ """\
332+ Feature: Example parameters reuse
333+ Scenario Outline: Check for example parameter re-use
334+ Given some <key> exists
335+ When I print <css_id>
336+ And I output "some value"
337+ And I echo <css_id>
338+ Then finish testing
339+
340+ Examples:
341+ | key | css_id |
342+ | foo | bar |
343+ | foo2 | bar2 |
344+
345+ """
346+ ),
347+ )
348+
349+ pytester .makepyfile (
350+ textwrap .dedent (
351+ """\
352+ from pytest_bdd import given, when, then, parsers, scenarios
353+
354+ scenarios('outline.feature')
355+
356+
357+ @given(parsers.parse("some {key} exists"))
358+ def some_key_exists(key):
359+ print(f"some {key} exists")
360+
361+ @when(parsers.parse('I print {css_id}'))
362+ def css_id(css_id):
363+ assert css_id in ('bar', 'bar2')
364+
365+ @when(parsers.parse('I echo {css_id}'))
366+ def echo_val(css_id):
367+ assert css_id in ('bar', 'bar2')
368+
369+ @when(parsers.re('I output "(?P<css_id>.+)"'))
370+ def i_output(css_id):
371+ assert css_id == 'some value'
372+
373+ @then('finish testing')
374+ def i_output():
375+ print("finished")
376+ assert True
377+
378+ """
379+ )
380+ )
381+ result = pytester .runpytest ("-s" )
382+ result .assert_outcomes (passed = 2 )
0 commit comments