Skip to content
Open
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 @@ -30,6 +30,7 @@ Removed
Fixed
+++++
* Made type annotations stronger and removed most of the ``typing.Any`` usages and ``# type: ignore`` annotations. `#658 <https://github.com/pytest-dev/pytest-bdd/pull/658>`_
* Empty docstrings are now correctly forwarded to step functions as an empty string instead of being silently dropped, which previously caused pytest to report a missing ``docstring`` fixture. `#809 <https://github.com/pytest-dev/pytest-bdd/issues/809>`_

Security
++++++++
Expand Down
2 changes: 1 addition & 1 deletion src/pytest_bdd/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def render(self, context: Mapping[str, object]) -> Scenario:
line_number=step.line_number,
keyword=step.keyword,
datatable=step.render_datatable(step.datatable, context) if step.datatable else None,
docstring=render_string(step.docstring, context) if step.docstring else None,
docstring=render_string(step.docstring, context) if step.docstring is not None else None,
)
for step in base_steps
]
Expand Down
50 changes: 50 additions & 0 deletions tests/steps/test_docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,56 @@ def _():
result.assert_outcomes(passed=1)


def test_steps_with_empty_docstring(pytester):
"""Regression test for #809.

An empty docstring must be passed to the step function as an empty
string. Before the fix it was dropped, and pytest then treated
``docstring`` as a missing fixture.
"""
pytester.makefile(
".feature",
empty_docstring=textwrap.dedent(
'''\
Feature: Empty docstring

Scenario: Step receives an empty docstring
Given a step has an empty docstring
"""
"""
'''
),
)
pytester.makeconftest(
textwrap.dedent(
r"""
from pytest_bdd import given
from pytest_bdd.utils import dump_obj


@given("a step has an empty docstring")
def _(docstring):
dump_obj(docstring)
"""
)
)
pytester.makepyfile(
textwrap.dedent(
"""\
from pytest_bdd import scenarios

scenarios("empty_docstring.feature")
"""
)
)

result = pytester.runpytest("-s")
result.assert_outcomes(passed=1)

docstrings = collect_dumped_objects(result)
assert docstrings == [""]


def test_docstring_step_argument_is_reserved_and_cannot_be_used(pytester):
pytester.makefile(
".feature",
Expand Down