Fix empty docstring delivery to step functions (#809)#810
Open
golikovichev wants to merge 1 commit intopytest-dev:masterfrom
Open
Fix empty docstring delivery to step functions (#809)#810golikovichev wants to merge 1 commit intopytest-dev:masterfrom
golikovichev wants to merge 1 commit intopytest-dev:masterfrom
Conversation
ScenarioTemplate.steps_from_template_steps used a truthy check (`if step.docstring`) when building the step list. An empty docstring is a valid value, but `""` is falsy, so the docstring was replaced with None. The step then looked like it had no docstring at all, and pytest fell back to fixture lookup, raising "fixture 'docstring' not found". Switched the check to `is not None` so empty docstrings are passed through as `""`. Added a regression test in tests/steps/test_docstring.py.
9084928 to
28ac968
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #809.
Problem
When a step has an empty docstring, pytest-bdd raises
fixture 'docstring' not found:The reproducer from the issue triggers this on
pytest-bdd 8.1.0.Cause
In
ScenarioTemplate.steps_from_template_steps(src/pytest_bdd/parser.py), the docstring of each rendered step was assigned with a truthy check:step.docstringhere is astr(set earlier inparse_stepsfromstep.docstring.content). For an empty docstring, that string is"", which is falsy, so the whole expression collapses toNone. The downstream check inscenario.pyonly forwards the docstring to the step function whenstep.docstring is not None, so the argument is never injected and pytest treatsdocstringas a missing fixture.The earlier line in
parse_stepsis fine because it tests theDocStringobject itself (always truthy when present) before reading.content.Fix
Switch the truthy check to
is not Noneso empty docstrings are forwarded as"":Tests
test_steps_with_empty_docstringintests/steps/test_docstring.py, following the style of the existing tests in that file.masterand passes with the fix.pytest tests/steps/test_docstring.py→ 5 passed).tests/steps,tests/parser/test_parser.py,tests/feature/test_scenario.py,tests/feature/test_outline.py→ 42 passed.CHANGES.rst entry added under the
UnreleasedFixed section.