From aa2ef257b86f1551edac274300ab6113a509ce2a Mon Sep 17 00:00:00 2001 From: Oleg Pidsadnyi Date: Sun, 22 Aug 2021 15:59:12 +0200 Subject: [PATCH 1/3] readme updated --- README.rst | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/README.rst b/README.rst index 5329a64fa..724c84006 100644 --- a/README.rst +++ b/README.rst @@ -112,7 +112,6 @@ Scenario decorator The scenario decorator can accept the following optional keyword arguments: * ``encoding`` - decode content of feature file in specific encoding. UTF-8 is default. -* ``example_converters`` - mapping to pass functions to convert example values provided in feature files. Functions decorated with the `scenario` decorator behave like a normal test function, and they will be executed after all scenario steps. @@ -555,25 +554,24 @@ The code will look like: @scenario( "outline.feature", "Outlined given, when, thens", - example_converters=dict(start=int, eat=float, left=str) ) def test_outlined(): pass - @given("there are cucumbers", target_fixture="start_cucumbers") + @given(parsers.parse("there are {start} cucumbers", target_fixture="start_cucumbers")) def start_cucumbers(start): assert isinstance(start, int) return dict(start=start) - @when("I eat cucumbers") + @when(parsers.parse("I eat {eat} cucumbers")) def eat_cucumbers(start_cucumbers, eat): assert isinstance(eat, float) start_cucumbers["eat"] = eat - @then("I should have cucumbers") + @then(parsers.parse("I should have {left} cucumbers")) def should_have_left_cucumbers(start_cucumbers, start, eat, left): assert isinstance(left, str) assert start - eat == int(left) @@ -672,17 +670,17 @@ The code will look like: """We don't need to do anything here, everything will be managed by the scenario decorator.""" - @given("there are cucumbers", target_fixture="start_cucumbers") + @given(parsers.parse("there are {start} cucumbers"), target_fixture="start_cucumbers") def start_cucumbers(start): return dict(start=start) - @when("I eat cucumbers") + @when(parsers.parse("I eat {eat} cucumbers")) def eat_cucumbers(start_cucumbers, start, eat): start_cucumbers["eat"] = eat - @then("I should have cucumbers") + @then(parsers.parse("I should have {left} cucumbers")) def should_have_left_cucumbers(start_cucumbers, start, eat, left): assert start - eat == left assert start_cucumbers["start"] == start @@ -1208,37 +1206,27 @@ As as side effect, the tool will validate the files for format errors, also some ordering of the types of the steps. -.. _Migration from 3.x.x: +.. _Migration from 4.x.x: -Migration of your tests from versions 3.x.x +Migration of your tests from versions 4.x.x ------------------------------------------- - -Given steps are no longer fixtures. In case it is needed to make given step setup a fixture -the target_fixture parameter should be used. - +The templated steps should use step argument parsers in order to match the scenario outlines +and get the values from the example tables. .. code-block:: python - @given("there's an article", target_fixture="article") - def there_is_an_article(): - return Article() - + # Instead of + # @given("there are in the box") + # def given_cucumbers(cucumbers): + # pass -Given steps no longer have fixture parameter. In fact the step may depend on multiple fixtures. -Just normal step declaration with the dependency injection should be used. - -.. code-block:: python - - @given("there's an article") - def there_is_an_article(article): + @given(parsers.parse("there are {cucumbers} in the box")) + def given_cucumbers(cucumbers): pass -Strict gherkin option is removed, so the ``strict_gherkin`` parameter can be removed from the scenario decorators -as well as ``bdd_strict_gherkin`` from the ini files. - -Step validation handlers for the hook ``pytest_bdd_step_validation_error`` should be removed. +Scenario `example_converters` are removed in favor of the converters provided on the step level. License From 4ba901a80a423be58ab822f82e393d81047b4804 Mon Sep 17 00:00:00 2001 From: Oleg Pidsadnyi Date: Sun, 22 Aug 2021 19:07:31 +0200 Subject: [PATCH 2/3] PR comments --- CHANGES.rst | 3 +++ README.rst | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ce575309a..378e447de 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,6 +3,9 @@ Changelog Unreleased ----------- + +This release introduces breaking changes, please refer to the :ref:`Migration from 4.x.x`. + - Removed ``example_converters`` from ``scenario(...)`` signature 4.1.0 diff --git a/README.rst b/README.rst index 724c84006..d1313c621 100644 --- a/README.rst +++ b/README.rst @@ -109,10 +109,6 @@ test_publish_article.py: Scenario decorator ------------------ -The scenario decorator can accept the following optional keyword arguments: - -* ``encoding`` - decode content of feature file in specific encoding. UTF-8 is default. - Functions decorated with the `scenario` decorator behave like a normal test function, and they will be executed after all scenario steps. You can consider it as a normal pytest test function, e.g. order fixtures there, @@ -1228,6 +1224,37 @@ and get the values from the example tables. Scenario `example_converters` are removed in favor of the converters provided on the step level. +.. _Migration from 3.x.x: + +Migration of your tests from versions 3.x.x +------------------------------------------- + + +Given steps are no longer fixtures. In case it is needed to make given step setup a fixture +the target_fixture parameter should be used. + + +.. code-block:: python + + @given("there's an article", target_fixture="article") + def there_is_an_article(): + return Article() + + +Given steps no longer have fixture parameter. In fact the step may depend on multiple fixtures. +Just normal step declaration with the dependency injection should be used. + +.. code-block:: python + + @given("there's an article") + def there_is_an_article(article): + pass + + +Strict gherkin option is removed, so the ``strict_gherkin`` parameter can be removed from the scenario decorators +as well as ``bdd_strict_gherkin`` from the ini files. + +Step validation handlers for the hook ``pytest_bdd_step_validation_error`` should be removed. License ------- From 5698c5cacec13c5fbf2893d95fc27cf35b558419 Mon Sep 17 00:00:00 2001 From: Oleg Pidsadnyi Date: Mon, 23 Aug 2021 18:59:23 +0200 Subject: [PATCH 3/3] Adding a comment that example values are no longer passed as fixtures --- README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index d1313c621..1f36736c1 100644 --- a/README.rst +++ b/README.rst @@ -1208,7 +1208,8 @@ Migration of your tests from versions 4.x.x ------------------------------------------- The templated steps should use step argument parsers in order to match the scenario outlines -and get the values from the example tables. +and get the values from the example tables. The values from the example tables are no longer +passed as fixtures. .. code-block:: python