Skip to content
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 @@ -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
----------
Expand Down
49 changes: 49 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------

Expand Down
63 changes: 63 additions & 0 deletions tests/steps/test_keyword.py
Original file line number Diff line number Diff line change
@@ -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)
Loading