Skip to content

Commit 626df4c

Browse files
authored
Merge pull request #713 from jsa34/asterisk-steps
Add test to use asterisks to continue step type instead of And or But
2 parents b3956b3 + 15b83ee commit 626df4c

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Unreleased
55
----------
66
- Update documentation to clarify that `--gherkin-terminal-reporter` needs to be used with `-v` or `-vv`.
77
- Drop compatibility with pytest < 7.0.0.
8+
- Continuation of steps using asterisks instead of And/But supported.
89

910
8.0.0b1
1011
----------

README.rst

+49
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,55 @@ default author.
156156
And there's an article
157157
158158
159+
Using Asterisks in Place of Keywords
160+
------------------------------------
161+
162+
To avoid redundancy or unnecessary repetition of keywords
163+
such as "And" or "But" in Gherkin scenarios,
164+
you can use an asterisk (*) as a shorthand.
165+
The asterisk acts as a wildcard, allowing for the same functionality
166+
without repeating the keyword explicitly.
167+
It improves readability by making the steps easier to follow,
168+
especially when the specific keyword does not add value to the scenario's clarity.
169+
170+
The asterisk will work the same as other step keywords - Given, When, Then - it follows.
171+
172+
For example:
173+
174+
.. code-block:: gherkin
175+
176+
Feature: Resource owner
177+
Scenario: I'm the author
178+
Given I'm an author
179+
* I have an article
180+
* I have a pen
181+
182+
183+
.. code-block:: python
184+
185+
from pytest_bdd import given
186+
187+
@given("I'm an author")
188+
def _():
189+
pass
190+
191+
@given("I have an article")
192+
def _():
193+
pass
194+
195+
@given("I have a pen")
196+
def _():
197+
pass
198+
199+
200+
In the scenario above, the asterisk (*) replaces the And or Given keywords.
201+
This allows for cleaner scenarios while still linking related steps together in the context of the scenario.
202+
203+
This approach is particularly useful when you have a series of steps
204+
that do not require explicitly stating whether they are part of the "Given", "When", or "Then" context
205+
but are part of the logical flow of the scenario.
206+
207+
159208
Step arguments
160209
--------------
161210

tests/steps/test_keyword.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import textwrap
2+
3+
4+
def test_asterisk_keyword(pytester):
5+
pytester.makefile(
6+
".feature",
7+
asterisk=textwrap.dedent(
8+
"""\
9+
Feature: Step continuation
10+
Scenario: Asterisk steps
11+
Given I am out shopping
12+
* I have eggs
13+
* I have milk
14+
* I have butter
15+
When I check my list
16+
Then I don't need anything
17+
"""
18+
),
19+
)
20+
pytester.makepyfile(
21+
textwrap.dedent(
22+
"""\
23+
import pytest
24+
from pytest_bdd import given, when, then, scenario
25+
26+
@scenario("asterisk.feature", "Asterisk steps")
27+
def test_asterisk_steps():
28+
pass
29+
30+
@given("I am out shopping")
31+
def _():
32+
pass
33+
34+
35+
@given("I have eggs")
36+
def _():
37+
pass
38+
39+
40+
@given("I have milk")
41+
def _():
42+
pass
43+
44+
45+
@given("I have butter")
46+
def _():
47+
pass
48+
49+
50+
@when("I check my list")
51+
def _():
52+
pass
53+
54+
55+
@then("I don't need anything")
56+
def _():
57+
pass
58+
59+
"""
60+
)
61+
)
62+
result = pytester.runpytest()
63+
result.assert_outcomes(passed=1)

0 commit comments

Comments
 (0)