@@ -81,6 +81,54 @@ def test_outline(request):
8181 # fmt: on
8282
8383
84+ def test_disallow_free_example_params (testdir ):
85+ """Test parametrized scenario when the test function lacks parameters."""
86+
87+ testdir .makefile (
88+ ".feature" ,
89+ outline = textwrap .dedent (
90+ """\
91+ Feature: Outline
92+ Scenario Outline: Outlined with wrong examples
93+ Given there are <start> cucumbers
94+ When I eat <eat> cucumbers
95+ Then I should have <left> cucumbers
96+
97+ Examples:
98+ | start | eat | left | unknown_param |
99+ | 12 | 5 | 7 | value |
100+
101+ """
102+ ),
103+ )
104+ testdir .makeconftest (textwrap .dedent (STEPS ))
105+
106+ testdir .makepyfile (
107+ textwrap .dedent (
108+ """\
109+ from pytest_bdd import scenario
110+
111+ @scenario(
112+ "outline.feature",
113+ "Outlined with wrong examples",
114+ allow_example_free_variables=False
115+ )
116+ def test_outline(request):
117+ pass
118+ """
119+ )
120+ )
121+ result = testdir .runpytest ()
122+ assert_outcomes (result , errors = 1 )
123+ result .stdout .fnmatch_lines (
124+ '*ScenarioExamplesNotValidError: Scenario "Outlined with wrong examples"*does not have valid examples*'
125+ )
126+ result .stdout .fnmatch_lines (
127+ "*Set of example parameters [[]'eat', 'left', 'start', 'unknown_param'[]] should be "
128+ "a subset of step parameters [[]'eat', 'left', 'start'[]]*"
129+ )
130+
131+
84132def test_outline_has_subset_of_parameters (testdir ):
85133 """Test parametrized scenario when the test function has a subset of the parameters of the examples."""
86134
@@ -108,8 +156,11 @@ def test_outline_has_subset_of_parameters(testdir):
108156 """\
109157 from pytest_bdd import scenario
110158
111- @scenario("outline.feature", "Outlined with subset of examples",
112- example_converters=dict(start=int, eat=float, left=str))
159+ @scenario(
160+ "outline.feature", "
161+ Outlined with subset of examples",
162+ allow_example_free_variables=True
163+ )
113164 def test_outline(request):
114165 pass
115166 """
@@ -120,7 +171,8 @@ def test_outline(request):
120171
121172
122173def test_wrongly_outlined_parameters_not_a_subset_of_examples (testdir ):
123- """Test parametrized scenario when the test function has a parameter set which is not a subset of those in the examples table."""
174+ """Test parametrized scenario when the test function has a parameter set
175+ which is not a subset of those in the examples table."""
124176
125177 testdir .makefile (
126178 ".feature" ,
@@ -145,8 +197,9 @@ def test_wrongly_outlined_parameters_not_a_subset_of_examples(testdir):
145197 textwrap .dedent (
146198 """\
147199 from pytest_bdd import scenario, then
200+ import pytest_bdd.parsers as parsers
148201
149- @scenario("outline.feature", "Outlined with wrong examples")
202+ @scenario("outline.feature", "Outlined with wrong examples", allow_step_free_variables=False )
150203 def test_outline(request):
151204 pass
152205
@@ -161,7 +214,7 @@ def stepdef(left, right):
161214 result .stdout .fnmatch_lines (
162215 '*ScenarioExamplesNotValidError: Scenario "Outlined with wrong examples"*does not have valid examples*' ,
163216 )
164- result .stdout .fnmatch_lines ("*should be a subset of example values [[]'eat', 'left', 'start'[]]. *" )
217+ result .stdout .fnmatch_lines ("*should be a subset of example parameters [[]'eat', 'left', 'start'[]]*" )
165218
166219
167220def test_wrong_vertical_examples_scenario (testdir ):
0 commit comments