From f189ae4495e7f1ab2af804a7a8142fbc017f8bae Mon Sep 17 00:00:00 2001 From: Jason Allen Date: Fri, 4 Oct 2024 17:00:06 +0100 Subject: [PATCH 1/2] Add test to use asterisks to continue step type instead of And or But --- tests/steps/test_keyword.py | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/steps/test_keyword.py diff --git a/tests/steps/test_keyword.py b/tests/steps/test_keyword.py new file mode 100644 index 00000000..8255ce60 --- /dev/null +++ b/tests/steps/test_keyword.py @@ -0,0 +1,63 @@ +import textwrap + + +def test_asterisk_keyword(pytester): + pytester.makefile( + ".feature", + asterisk=textwrap.dedent( + """\ + Feature: Step continuation + Scenario: Asterisk steps + Given I am out shopping + * I have eggs + * I have milk + * I have butter + When I check my list + Then I don't need anything + """ + ), + ) + pytester.makepyfile( + textwrap.dedent( + """\ + import pytest + from pytest_bdd import given, when, then, scenario + + @scenario("asterisk.feature", "Asterisk steps") + def test_asterisk_steps(): + pass + + @given("I am out shopping") + def _(): + pass + + + @given("I have eggs") + def _(): + pass + + + @given("I have milk") + def _(): + pass + + + @given("I have butter") + def _(): + pass + + + @when("I check my list") + def _(): + pass + + + @then("I don't need anything") + def _(): + pass + + """ + ) + ) + result = pytester.runpytest() + result.assert_outcomes(passed=1) From 15b83ee41b6c000da25a16b85d2a35b9755b9a1f Mon Sep 17 00:00:00 2001 From: Jason Allen Date: Sat, 5 Oct 2024 10:13:54 +0100 Subject: [PATCH 2/2] Add changelog entry. Add section to README to exemplify usage. --- CHANGES.rst | 1 + README.rst | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index ebfb239f..b09b608e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,7 @@ Unreleased ---------- - Update documentation to clarify that `--gherkin-terminal-reporter` needs to be used with `-v` or `-vv`. - Drop compatibility with pytest < 7.0.0. +- Continuation of steps using asterisks instead of And/But supported. 8.0.0b1 ---------- diff --git a/README.rst b/README.rst index 5bd1d099..c0814eac 100644 --- a/README.rst +++ b/README.rst @@ -156,6 +156,55 @@ default author. And there's an article +Using Asterisks in Place of Keywords +------------------------------------ + +To avoid redundancy or unnecessary repetition of keywords +such as "And" or "But" in Gherkin scenarios, +you can use an asterisk (*) as a shorthand. +The asterisk acts as a wildcard, allowing for the same functionality +without repeating the keyword explicitly. +It improves readability by making the steps easier to follow, +especially when the specific keyword does not add value to the scenario's clarity. + +The asterisk will work the same as other step keywords - Given, When, Then - it follows. + +For example: + +.. code-block:: gherkin + + Feature: Resource owner + Scenario: I'm the author + Given I'm an author + * I have an article + * I have a pen + + +.. code-block:: python + + from pytest_bdd import given + + @given("I'm an author") + def _(): + pass + + @given("I have an article") + def _(): + pass + + @given("I have a pen") + def _(): + pass + + +In the scenario above, the asterisk (*) replaces the And or Given keywords. +This allows for cleaner scenarios while still linking related steps together in the context of the scenario. + +This approach is particularly useful when you have a series of steps +that do not require explicitly stating whether they are part of the "Given", "When", or "Then" context +but are part of the logical flow of the scenario. + + Step arguments --------------