Skip to content

Commit 42f7560

Browse files
committed
Response to feedback
1 parent 7e3d6dc commit 42f7560

File tree

2 files changed

+85
-22
lines changed

2 files changed

+85
-22
lines changed

README.rst

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ Example:
514514
assert cucumbers["start"] - cucumbers["eat"] == left
515515
516516
517-
Datatable Argument and Accessing the Datatable
518-
--------------------------------------------
517+
Datatables
518+
----------
519519

520520
The ``datatable`` argument allows you to utilise data tables defined in your Gherkin scenarios
521521
directly within your test functions. This is particularly useful for scenarios that require tabular data as input,
@@ -606,8 +606,8 @@ Full example:
606606
assert users_have_correct_permissions(users, expected_permissions)
607607
608608
609-
Docstring Argument and Accessing the Docstring
610-
---------------------------------------------
609+
Docstrings
610+
----------
611611

612612
The `docstring` argument allows you to access the Gherkin docstring defined in your steps as a multiline string.
613613
The content of the docstring is passed as a single string, with each line separated by `\\n`.
@@ -635,48 +635,54 @@ Full example:
635635
Feature: Docstring
636636
637637
Scenario: Step with docstrings
638-
Given a step has a docstring
638+
Given some steps will have docstrings
639+
640+
Then a step has a docstring
639641
"""
640-
This is a given docstring
642+
This is a docstring
641643
on two lines
642644
"""
643645
644-
When a step provides a docstring with lower indentation
646+
And a step provides a docstring with lower indentation
645647
"""
646648
This is a when docstring
647649
"""
648650
649651
And this step has no docstring
650652
651-
Then this step has a greater indentation
653+
And this step has a greater indentation
652654
"""
653-
This is a then docstring
655+
This is a docstring
654656
"""
655657
656658
And this step has no docstring
657659
658660
.. code-block:: python
659661
660-
from pytest_bdd import given, when, then
662+
from pytest_bdd import given, then
663+
664+
@given("some steps will have docstrings")
665+
def _():
666+
pass
661667
662-
@given("a step has a docstring")
668+
@then("a step has a docstring")
663669
def _(docstring):
664670
assert docstring == "This is a given docstring\non two lines"
665671
666-
@when("a step provides a docstring with lower indentation")
672+
@then("a step provides a docstring with lower indentation")
667673
def _(docstring):
668-
print(docstring)
674+
assert docstring == "This is a when docstring"
669675
670676
@then("this step has a greater indentation")
671677
def _(docstring):
672-
print(docstring)
678+
assert docstring == "This is a when docstring"
673679
674680
@then("this step has no docstring")
675681
def _():
676682
pass
677683
678684
679-
.. NOTE:: The docstring argument can only be used for steps that have an associated docstring.
685+
.. note:: The ``docstring`` argument can only be used for steps that have an associated docstring.
680686
Otherwise, an error will be thrown.
681687

682688
Organizing your scenarios

tests/steps/test_docstring.py

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ def test_steps_with_docstrings(pytester):
3434
pytester.makeconftest(
3535
textwrap.dedent(
3636
r"""
37-
from pytest_bdd import given, when, then, parsers
37+
from pytest_bdd import given, when, then
3838
from pytest_bdd.utils import dump_obj
39-
import re
4039
4140
4241
@given("a step has a docstring")
@@ -80,9 +79,7 @@ def test_docstring():
8079
result.assert_outcomes(passed=1)
8180

8281
docstrings = collect_dumped_objects(result)
83-
assert docstrings[0] == "This is a given docstring"
84-
assert docstrings[1] == "This is a when docstring"
85-
assert docstrings[2] == "This is a then docstring"
82+
assert docstrings == ["This is a given docstring", "This is a when docstring", "This is a then docstring"]
8683

8784

8885
def test_steps_with_missing_docstring(pytester):
@@ -106,8 +103,7 @@ def test_steps_with_missing_docstring(pytester):
106103
pytester.makeconftest(
107104
textwrap.dedent(
108105
"""\
109-
from pytest_bdd import given, when, then, parsers
110-
from re import DOTALL
106+
from pytest_bdd import given, when, then
111107
112108
113109
@given("this step has a docstring")
@@ -142,3 +138,64 @@ def test_docstring():
142138
result = pytester.runpytest("-s")
143139
result.assert_outcomes(failed=1)
144140
result.stdout.fnmatch_lines(["*fixture 'docstring' not found*"])
141+
142+
143+
def test_steps_with_docstring_missing_argument_in_step_def(pytester):
144+
pytester.makefile(
145+
".feature",
146+
missing_docstring_arg=textwrap.dedent(
147+
'''\
148+
Feature: Missing docstring
149+
150+
Scenario: Docstring arg is missing for a step definition
151+
Given this step has a docstring
152+
"""
153+
This is a given docstring
154+
"""
155+
156+
When this step has a docstring but no docstring argument
157+
"""
158+
This is a when docstring
159+
"""
160+
161+
Then the test passes
162+
'''
163+
),
164+
)
165+
pytester.makeconftest(
166+
textwrap.dedent(
167+
"""\
168+
from pytest_bdd import given, when, then
169+
170+
171+
@given("this step has a docstring")
172+
def _(docstring):
173+
print(docstring)
174+
175+
176+
@when("this step has a docstring but no docstring argument")
177+
def _():
178+
pass
179+
180+
181+
@then("the test passes")
182+
def _():
183+
pass
184+
185+
"""
186+
)
187+
)
188+
189+
pytester.makepyfile(
190+
textwrap.dedent(
191+
"""\
192+
from pytest_bdd import scenario
193+
194+
@scenario("missing_docstring_arg.feature", "Docstring arg is missing for a step definition")
195+
def test_docstring():
196+
pass
197+
"""
198+
)
199+
)
200+
result = pytester.runpytest("-s")
201+
result.assert_outcomes(passed=1)

0 commit comments

Comments
 (0)