Skip to content

Commit 62842c3

Browse files
Kostiantyn Goloveshkoolegpidsadnyi
authored andcommitted
Refuse combining of scenario outline and pytest parametrization
* Update documentation Discussed in #445, #448
1 parent 5cb652e commit 62842c3

File tree

1 file changed

+8
-60
lines changed

1 file changed

+8
-60
lines changed

README.rst

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -638,66 +638,6 @@ This is allowed as long as parameter names do not clash:
638638
| tomatoes |
639639
640640
641-
Combine scenario outline and pytest parametrization
642-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
643-
644-
It's also possible to parametrize the scenario on the python side.
645-
The reason for this is that it is sometimes not needed to mention example table for every scenario.
646-
647-
The code will look like:
648-
649-
.. code-block:: python
650-
651-
import pytest
652-
from pytest_bdd import scenario, given, when, then, parsers
653-
654-
655-
# Here we use pytest to parametrize the test with the parameters table
656-
@pytest.mark.parametrize(
657-
["start", "eat", "left"],
658-
[(12, 5, 7)],
659-
)
660-
@scenario(
661-
"parametrized.feature",
662-
"Parametrized given, when, then",
663-
)
664-
# Note that we should take the same arguments in the test function that we use
665-
# for the test parametrization either directly or indirectly (fixtures depend on them).
666-
def test_parametrized(start, eat, left):
667-
"""We don't need to do anything here, everything will be managed by the scenario decorator."""
668-
669-
670-
@given(parsers.parse("there are {start:d} cucumbers"), target_fixture="start_cucumbers")
671-
def start_cucumbers(start):
672-
return dict(start=start)
673-
674-
675-
@when(parsers.parse("I eat {eat:d} cucumbers"))
676-
def eat_cucumbers(start_cucumbers, start, eat):
677-
start_cucumbers["eat"] = eat
678-
679-
680-
@then(parsers.parse("I should have {left:d} cucumbers"))
681-
def should_have_left_cucumbers(start_cucumbers, start, eat, left):
682-
assert start - eat == left
683-
assert start_cucumbers["start"] == start
684-
assert start_cucumbers["eat"] == eat
685-
686-
687-
With a parametrized.feature file:
688-
689-
.. code-block:: gherkin
690-
691-
Feature: parametrized
692-
Scenario: Parametrized given, when, then
693-
Given there are <start> cucumbers
694-
When I eat <eat> cucumbers
695-
Then I should have <left> cucumbers
696-
697-
698-
The significant downside of this approach is inability to see the test table from the feature file.
699-
700-
701641
Organizing your scenarios
702642
-------------------------
703643

@@ -1179,6 +1119,8 @@ ordering of the types of the steps.
11791119
Migration of your tests from versions 4.x.x
11801120
-------------------------------------------
11811121

1122+
Replace usage of <parameter> inside step definitions with parsed {parameter}
1123+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11821124
Templated steps (e.g. ``@given("there are <start> cucumbers")``) should now the use step argument parsers in order to match the scenario outlines and get the values from the example tables. The values from the example tables are no longer passed as fixtures, although if you define your step to use a parser, the parameters will be still provided as fixtures.
11831125

11841126
.. code-block:: python
@@ -1219,6 +1161,12 @@ Scenario `example_converters` are removed in favor of the converters provided on
12191161
pass
12201162
12211163
1164+
Refuse combining scenario outline and pytest parametrization
1165+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1166+
The significant downside of combining scenario outline and pytest parametrization approach was inability to see the
1167+
test table from the feature file.
1168+
1169+
12221170
.. _Migration from 3.x.x:
12231171

12241172
Migration of your tests from versions 3.x.x

0 commit comments

Comments
 (0)