Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused example param validation #499

Merged
merged 7 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ This release introduces breaking changes in order to be more in line with the of
- Step arguments are no longer fixtures (olegpidsadnyi)
- Drop support of python 3.6, pytest 4 (elchupanebrej)
- 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)
- Scenario outlines unused example parameter validation is removed (olegpidsadnyi)



Expand Down
8 changes: 0 additions & 8 deletions pytest_bdd/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ class ExamplesNotValidError(ScenarioValidationError):
"""Example table is not valid."""


class ScenarioExamplesNotValidError(ScenarioValidationError):
"""Scenario steps parameters do not match declared scenario examples."""


class FeatureExamplesNotValidError(ScenarioValidationError):
"""Feature example table is not valid."""


class StepDefinitionNotFoundError(Exception):
"""Step definition not found."""

Expand Down
4 changes: 0 additions & 4 deletions pytest_bdd/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def pytest_bdd_step_error(request, feature, scenario, step, step_func, step_func
"""Called when step function failed to execute."""


def pytest_bdd_step_validation_error(request, feature, scenario, step, step_func, step_func_args, exception):
"""Called when step failed to validate."""


def pytest_bdd_step_func_lookup_error(request, feature, scenario, step, exception):
"""Called when step lookup failed."""

Expand Down
15 changes: 0 additions & 15 deletions pytest_bdd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,21 +233,6 @@ def render(self, context: typing.Mapping[str, typing.Any]) -> "Scenario":
]
return Scenario(feature=self.feature, name=self.name, line_number=self.line_number, steps=steps, tags=self.tags)

def validate(self):
youtux marked this conversation as resolved.
Show resolved Hide resolved
"""Validate the scenario.

:raises ScenarioValidationError: when scenario is not valid
"""
params = frozenset(sum((list(step.params) for step in self.steps), []))
example_params = set(self.examples.example_params)
if params and example_params and params != example_params:
raise exceptions.ScenarioExamplesNotValidError(
"""Scenario "{}" in the feature "{}" has not valid examples. """
"""Set of step parameters {} should match set of example values {}.""".format(
self.name, self.feature.filename, sorted(params), sorted(example_params)
)
)


class Scenario:

Expand Down
3 changes: 0 additions & 3 deletions pytest_bdd/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,6 @@ def scenario(feature_name: str, scenario_name: str, encoding: str = "utf-8", fea
f'Scenario "{scenario_name}" in feature "{feature_name}" in {feature.filename} is not found.'
)

# Validate the scenario
scenario.validate()

return _get_scenario_decorator(
feature=feature, feature_name=feature_name, templated_scenario=scenario, scenario_name=scenario_name
)
Expand Down
17 changes: 7 additions & 10 deletions tests/feature/test_outline.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,23 @@ def test_outline(request):
# fmt: on


def test_wrongly_outlined(testdir):
def test_unused_params(testdir):
"""Test parametrized scenario when the test function lacks parameters."""

testdir.makefile(
".feature",
outline=textwrap.dedent(
"""\
Feature: Outline
Scenario Outline: Outlined with wrong examples
youtux marked this conversation as resolved.
Show resolved Hide resolved
Scenario Outline: Outlined with unused params
Given there are <start> cucumbers
When I eat <eat> cucumbers
# And commented out step with <unused_param>
Then I should have <left> cucumbers

Examples:
| start | eat | left | unknown_param |
| 12 | 5 | 7 | value |
| start | eat | left | unused_param |
| 12 | 5 | 7 | value |

"""
),
Expand All @@ -106,18 +107,14 @@ def test_wrongly_outlined(testdir):
"""\
from pytest_bdd import scenario

@scenario("outline.feature", "Outlined with wrong examples")
@scenario("outline.feature", "Outlined with unused params")
def test_outline(request):
pass
"""
)
)
result = testdir.runpytest()
assert_outcomes(result, errors=1)
result.stdout.fnmatch_lines(
'*ScenarioExamplesNotValidError: Scenario "Outlined with wrong examples"*has not valid examples*',
)
result.stdout.fnmatch_lines("*should match set of example values [[]'eat', 'left', 'start', 'unknown_param'[]].*")
assert_outcomes(result, passed=1)


def test_outlined_with_other_fixtures(testdir):
Expand Down