Skip to content

Empty docstring results in "fixture not found" #809

@sed-i

Description

@sed-i

Describe the bug
I have a couple scenarios that reuse the same test methods.
In one of my "When"s, I attempt to pass an empty docstring.
As a result, pytest-bdd complains for that particular test that the docstring fixture does not exist.

file /home/aegis/.cache/uv/builds-v0/.tmpsi0712/lib/python3.12/site-packages/pytest_bdd/scenario.py, line 296
          def scenario_wrapper(request: FixtureRequest, _pytest_bdd_example: dict[str, str]) -> Any:
E       fixture 'docstring' not found
>       available fixtures: _pytest_bdd_example, abort_on_fail, anyio_backend, anyio_backend_name, anyio_backend_options, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, context, doctest_namespace, event_loop, free_tcp_port, free_tcp_port_factory, free_udp_port, free_udp_port_factory, interface_tester, loki_charm, loki_container, monkeypatch, ops_test, pytestbdd_stepdef_given_rules, pytestbdd_stepdef_given_trace, pytestbdd_stepdef_then_modified rules match, pytestbdd_stepdef_then_trace, pytestbdd_stepdef_when_extra labels are injected, pytestbdd_stepdef_when_trace, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory, unused_tcp_port, unused_tcp_port_factory, unused_udp_port, unused_udp_port_factory
>       use 'pytest --fixtures [testpath]' for help on them.

/home/aegis/.cache/uv/builds-v0/.tmpsi0712/lib/python3.12/site-packages/pytest_bdd/scenario.py:296

To Reproduce

  Scenario: Empty extra labels leaves rules unchanged
    Given rules
      """
      groups:
        - rules:
            - labels:
                severity: warning
                team: some-team
      """
    When extra labels are injected
      """
      """
    Then modified rules match
      """
      groups:
        - rules:
            - labels:
                severity: warning
                team: some-team
      """
@when("extra labels are injected", target_fixture="modified_rules")
def when_extra_labels_injected(docstring, rules):
    extra_labels = yaml.safe_load(docstring) or {}

    return "..."

Expected behavior
I expected the docstring fixture to contain the the empty string, "".

Additional context
As a workaround, I changed the docstring to

"""
+---
"""

Version

  • pytest version: 8.3.5
  • pytest-bdd version: 8.1.0
  • OS: Ubuntu 26.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions