From 496fabbd14fd3fb158fa48a56caf86b7b19d1d6b Mon Sep 17 00:00:00 2001 From: Oleg Pidsadnyi Date: Sun, 13 Feb 2022 11:54:58 +0100 Subject: [PATCH 1/6] Scenario example validation restrictions removed. --- pytest_bdd/exceptions.py | 8 -------- pytest_bdd/parser.py | 15 ++------------- tests/feature/test_outline.py | 15 ++++++--------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/pytest_bdd/exceptions.py b/pytest_bdd/exceptions.py index 25706749..150ba96d 100644 --- a/pytest_bdd/exceptions.py +++ b/pytest_bdd/exceptions.py @@ -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.""" diff --git a/pytest_bdd/parser.py b/pytest_bdd/parser.py index 296ff522..15c1b9c1 100644 --- a/pytest_bdd/parser.py +++ b/pytest_bdd/parser.py @@ -234,19 +234,8 @@ 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): - """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) - ) - ) + """Validate the scenario.""" + pass class Scenario: diff --git a/tests/feature/test_outline.py b/tests/feature/test_outline.py index f3aaf845..fd7913ca 100644 --- a/tests/feature/test_outline.py +++ b/tests/feature/test_outline.py @@ -87,14 +87,15 @@ def test_wrongly_outlined(testdir): outline=textwrap.dedent( """\ Feature: Outline - Scenario Outline: Outlined with wrong examples + Scenario Outline: Outlined with unused params Given there are cucumbers When I eat cucumbers + # And commented out step with Then I should have cucumbers Examples: - | start | eat | left | unknown_param | - | 12 | 5 | 7 | value | + | start | eat | left | unused_param | + | 12 | 5 | 7 | value | """ ), @@ -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): From 162ab57379e410b4311ad82b20d188d9b227be0d Mon Sep 17 00:00:00 2001 From: Oleg Pidsadnyi Date: Sun, 13 Feb 2022 11:56:12 +0100 Subject: [PATCH 2/6] Changelog updated --- CHANGES.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.rst b/CHANGES.rst index 661a8058..4ddf0174 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,7 @@ This release introduces breaking changes in order to be more in line with the of - Removed feature level examples for the gherkin compatibility (olegpidsadnyi) - Removed vertical examples for the gherkin compatibility (olegpidsadnyi) - Step arguments are no longer fixtures (olegpidsadnyi) +- Scenario outlines unused example parameter validation is removed (olegpidsadnyi) From c1df0d353e3d91cf22a530256039ccd02ab3702b Mon Sep 17 00:00:00 2001 From: Oleg Pidsadnyi Date: Sun, 13 Feb 2022 12:05:03 +0100 Subject: [PATCH 3/6] Fixing the lint --- pytest_bdd/cucumber_json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_bdd/cucumber_json.py b/pytest_bdd/cucumber_json.py index 07b5e6ea..3102a503 100644 --- a/pytest_bdd/cucumber_json.py +++ b/pytest_bdd/cucumber_json.py @@ -61,7 +61,7 @@ def _get_result(self, step, report, error_message=False): result = {"status": "failed", "error_message": str(report.longrepr) if error_message else ""} elif report.skipped: result = {"status": "skipped"} - result["duration"] = int(math.floor((10 ** 9) * step["duration"])) # nanosec + result["duration"] = int(math.floor((10**9) * step["duration"])) # nanosec return result def _serialize_tags(self, item): From 2f5fdd53fecb3f72ccd7c2c2fc63dd5c48fc8992 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 13 Feb 2022 11:05:20 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pytest_bdd/cucumber_json.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest_bdd/cucumber_json.py b/pytest_bdd/cucumber_json.py index 3102a503..07b5e6ea 100644 --- a/pytest_bdd/cucumber_json.py +++ b/pytest_bdd/cucumber_json.py @@ -61,7 +61,7 @@ def _get_result(self, step, report, error_message=False): result = {"status": "failed", "error_message": str(report.longrepr) if error_message else ""} elif report.skipped: result = {"status": "skipped"} - result["duration"] = int(math.floor((10**9) * step["duration"])) # nanosec + result["duration"] = int(math.floor((10 ** 9) * step["duration"])) # nanosec return result def _serialize_tags(self, item): From 1bd69982639ac1fb3dc77e541a82f00ea3097f2c Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Thu, 24 Feb 2022 13:19:14 +0100 Subject: [PATCH 5/6] Remove unused code --- pytest_bdd/hooks.py | 4 ---- pytest_bdd/parser.py | 4 ---- pytest_bdd/scenario.py | 3 --- 3 files changed, 11 deletions(-) diff --git a/pytest_bdd/hooks.py b/pytest_bdd/hooks.py index b3ec01e5..5d69421c 100644 --- a/pytest_bdd/hooks.py +++ b/pytest_bdd/hooks.py @@ -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.""" diff --git a/pytest_bdd/parser.py b/pytest_bdd/parser.py index 15c1b9c1..621a305b 100644 --- a/pytest_bdd/parser.py +++ b/pytest_bdd/parser.py @@ -233,10 +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): - """Validate the scenario.""" - pass - class Scenario: diff --git a/pytest_bdd/scenario.py b/pytest_bdd/scenario.py index 38ad4033..c7dd2380 100644 --- a/pytest_bdd/scenario.py +++ b/pytest_bdd/scenario.py @@ -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 ) From 5bdeee606c8a851167c52c18428bb854bb5c49ea Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Thu, 24 Feb 2022 13:34:21 +0100 Subject: [PATCH 6/6] Fix test name --- tests/feature/test_outline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/feature/test_outline.py b/tests/feature/test_outline.py index fd7913ca..98984f40 100644 --- a/tests/feature/test_outline.py +++ b/tests/feature/test_outline.py @@ -79,7 +79,7 @@ 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(