@@ -78,6 +78,54 @@ def test_outline(request):
7878 result .assert_outcomes (passed = 2 )
7979
8080
81+ def test_disallow_free_example_params (testdir ):
82+ """Test parametrized scenario when the test function lacks parameters."""
83+
84+ testdir .makefile (
85+ ".feature" ,
86+ outline = textwrap .dedent (
87+ """\
88+ Feature: Outline
89+ Scenario Outline: Outlined with wrong examples
90+ Given there are <start> cucumbers
91+ When I eat <eat> cucumbers
92+ Then I should have <left> cucumbers
93+
94+ Examples:
95+ | start | eat | left | unknown_param |
96+ | 12 | 5 | 7 | value |
97+
98+ """
99+ ),
100+ )
101+ testdir .makeconftest (textwrap .dedent (STEPS ))
102+
103+ testdir .makepyfile (
104+ textwrap .dedent (
105+ """\
106+ from pytest_bdd import scenario
107+
108+ @scenario(
109+ "outline.feature",
110+ "Outlined with wrong examples",
111+ allow_example_free_variables=False
112+ )
113+ def test_outline(request):
114+ pass
115+ """
116+ )
117+ )
118+ result = testdir .runpytest ()
119+ assert_outcomes (result , errors = 1 )
120+ result .stdout .fnmatch_lines (
121+ '*ScenarioExamplesNotValidError: Scenario "Outlined with wrong examples"*does not have valid examples*'
122+ )
123+ result .stdout .fnmatch_lines (
124+ "*Set of example parameters [[]'eat', 'left', 'start', 'unknown_param'[]] should be "
125+ "a subset of step parameters [[]'eat', 'left', 'start'[]]*"
126+ )
127+
128+
81129def test_outline_has_subset_of_parameters (testdir ):
82130 """Test parametrized scenario when the test function has a subset of the parameters of the examples."""
83131
@@ -106,7 +154,7 @@ def test_outline_has_subset_of_parameters(testdir):
106154 from pytest_bdd import scenario
107155
108156 @scenario("outline.feature", "Outlined with subset of examples",
109- example_converters=dict(start=int, eat=float, left=str))
157+ example_converters=dict(start=int, eat=float, left=str), allow_example_free_variables=True )
110158 def test_outline(request):
111159 pass
112160 """
@@ -142,8 +190,9 @@ def test_wrongly_outlined_parameters_not_a_subset_of_examples(testdir):
142190 textwrap .dedent (
143191 """\
144192 from pytest_bdd import scenario, then
193+ import pytest_bdd.parsers as parsers
145194
146- @scenario("outline.feature", "Outlined with wrong examples")
195+ @scenario("outline.feature", "Outlined with wrong examples", allow_step_free_variables=False )
147196 def test_outline(request):
148197 pass
149198
@@ -158,7 +207,7 @@ def stepdef(left, right):
158207 result .stdout .fnmatch_lines (
159208 '*ScenarioExamplesNotValidError: Scenario "Outlined with wrong examples"*does not have valid examples*' ,
160209 )
161- result .stdout .fnmatch_lines ("*should be a subset of example values [[]'eat', 'left', 'start'[]]. *" )
210+ result .stdout .fnmatch_lines ("*should be a subset of example parameters [[]'eat', 'left', 'start'[]]*" )
162211
163212
164213def test_wrong_vertical_examples_scenario (testdir ):
0 commit comments