Skip to content

Commit ddcbeb5

Browse files
authored
Merge pull request #499 from pytest-dev/unused-params-validation
remove unused example param validation
2 parents d4f74d2 + 5bdeee6 commit ddcbeb5

File tree

6 files changed

+8
-40
lines changed

6 files changed

+8
-40
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This release introduces breaking changes in order to be more in line with the of
1212
- Step arguments are no longer fixtures (olegpidsadnyi)
1313
- Drop support of python 3.6, pytest 4 (elchupanebrej)
1414
- Step definitions can have "yield" statements again (4.0 release broke it). They will be executed as normal fixtures: code after the yield is executed during teardown of the test. (youtux)
15+
- Scenario outlines unused example parameter validation is removed (olegpidsadnyi)
1516

1617

1718

pytest_bdd/exceptions.py

-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ class ExamplesNotValidError(ScenarioValidationError):
1717
"""Example table is not valid."""
1818

1919

20-
class ScenarioExamplesNotValidError(ScenarioValidationError):
21-
"""Scenario steps parameters do not match declared scenario examples."""
22-
23-
24-
class FeatureExamplesNotValidError(ScenarioValidationError):
25-
"""Feature example table is not valid."""
26-
27-
2820
class StepDefinitionNotFoundError(Exception):
2921
"""Step definition not found."""
3022

pytest_bdd/hooks.py

-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ def pytest_bdd_step_error(request, feature, scenario, step, step_func, step_func
2727
"""Called when step function failed to execute."""
2828

2929

30-
def pytest_bdd_step_validation_error(request, feature, scenario, step, step_func, step_func_args, exception):
31-
"""Called when step failed to validate."""
32-
33-
3430
def pytest_bdd_step_func_lookup_error(request, feature, scenario, step, exception):
3531
"""Called when step lookup failed."""
3632

pytest_bdd/parser.py

-15
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,6 @@ def render(self, context: typing.Mapping[str, typing.Any]) -> "Scenario":
233233
]
234234
return Scenario(feature=self.feature, name=self.name, line_number=self.line_number, steps=steps, tags=self.tags)
235235

236-
def validate(self):
237-
"""Validate the scenario.
238-
239-
:raises ScenarioValidationError: when scenario is not valid
240-
"""
241-
params = frozenset(sum((list(step.params) for step in self.steps), []))
242-
example_params = set(self.examples.example_params)
243-
if params and example_params and params != example_params:
244-
raise exceptions.ScenarioExamplesNotValidError(
245-
"""Scenario "{}" in the feature "{}" has not valid examples. """
246-
"""Set of step parameters {} should match set of example values {}.""".format(
247-
self.name, self.feature.filename, sorted(params), sorted(example_params)
248-
)
249-
)
250-
251236

252237
class Scenario:
253238

pytest_bdd/scenario.py

-3
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,6 @@ def scenario(feature_name: str, scenario_name: str, encoding: str = "utf-8", fea
234234
f'Scenario "{scenario_name}" in feature "{feature_name}" in {feature.filename} is not found.'
235235
)
236236

237-
# Validate the scenario
238-
scenario.validate()
239-
240237
return _get_scenario_decorator(
241238
feature=feature, feature_name=feature_name, templated_scenario=scenario, scenario_name=scenario_name
242239
)

tests/feature/test_outline.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,23 @@ def test_outline(request):
7979
# fmt: on
8080

8181

82-
def test_wrongly_outlined(testdir):
82+
def test_unused_params(testdir):
8383
"""Test parametrized scenario when the test function lacks parameters."""
8484

8585
testdir.makefile(
8686
".feature",
8787
outline=textwrap.dedent(
8888
"""\
8989
Feature: Outline
90-
Scenario Outline: Outlined with wrong examples
90+
Scenario Outline: Outlined with unused params
9191
Given there are <start> cucumbers
9292
When I eat <eat> cucumbers
93+
# And commented out step with <unused_param>
9394
Then I should have <left> cucumbers
9495
9596
Examples:
96-
| start | eat | left | unknown_param |
97-
| 12 | 5 | 7 | value |
97+
| start | eat | left | unused_param |
98+
| 12 | 5 | 7 | value |
9899
99100
"""
100101
),
@@ -106,18 +107,14 @@ def test_wrongly_outlined(testdir):
106107
"""\
107108
from pytest_bdd import scenario
108109
109-
@scenario("outline.feature", "Outlined with wrong examples")
110+
@scenario("outline.feature", "Outlined with unused params")
110111
def test_outline(request):
111112
pass
112113
"""
113114
)
114115
)
115116
result = testdir.runpytest()
116-
assert_outcomes(result, errors=1)
117-
result.stdout.fnmatch_lines(
118-
'*ScenarioExamplesNotValidError: Scenario "Outlined with wrong examples"*has not valid examples*',
119-
)
120-
result.stdout.fnmatch_lines("*should match set of example values [[]'eat', 'left', 'start', 'unknown_param'[]].*")
117+
assert_outcomes(result, passed=1)
121118

122119

123120
def test_outlined_with_other_fixtures(testdir):

0 commit comments

Comments
 (0)