pytest-dev / pytest-bdd

BDD library for the pytest runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.32k stars 221 forks source link

`iterparentnodeids` removed from pytest #668

Closed The-Compiler closed 9 months ago

The-Compiler commented 10 months ago

Running against the current pytest main branch results in:

File "/__w/qutebrowser/qutebrowser/.tox/bleeding-qt5/lib/python3.11/site-packages/pytest_bdd/__init__.py", line 4, in <module>
    from pytest_bdd.scenario import scenario, scenarios
  File "/__w/qutebrowser/qutebrowser/.tox/bleeding-qt5/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 175, in exec_module
    exec(co, module.__dict__)
  File "/__w/qutebrowser/qutebrowser/.tox/bleeding-qt5/lib/python3.11/site-packages/pytest_bdd/scenario.py", line 23, in <module>
    from _pytest.nodes import iterparentnodeids
ImportError: cannot import name 'iterparentnodeids' from '_pytest.nodes' (/__w/qutebrowser/qutebrowser/.tox/bleeding-qt5/lib/python3.11/site-packages/_pytest/nodes.py)

due to:

Relevant changelog entry:

  • The _pytest.nodes.iterparentnodeids() function is removed without replacement. Prefer to traverse the node hierarchy itself instead. If you really need to, copy the function from the previous pytest release.

Relevant code from before it was removed (with SEP = "/"):

def iterparentnodeids(nodeid: str) -> Iterator[str]:
    """Return the parent node IDs of a given node ID, inclusive.
    For the node ID
        "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source"
    the result would be
        ""
        "testing"
        "testing/code"
        "testing/code/test_excinfo.py"
        "testing/code/test_excinfo.py::TestFormattedExcinfo"
        "testing/code/test_excinfo.py::TestFormattedExcinfo::test_repr_source"
    Note that / components are only considered until the first ::.
    """
    pos = 0
    first_colons: Optional[int] = nodeid.find("::")
    if first_colons == -1:
        first_colons = None
    # The root Session node - always present.
    yield ""
    # Eagerly consume SEP parts until first colons.
    while True:
        at = nodeid.find(SEP, pos, first_colons)
        if at == -1:
            break
        if at > 0:
            yield nodeid[:at]
        pos = at + len(SEP)
    # Eagerly consume :: parts.
    while True:
        at = nodeid.find("::", pos)
        if at == -1:
            break
        if at > 0:
            yield nodeid[:at]
        pos = at + len("::")
    # The node ID itself.
    if nodeid:
        yield nodeid
youtux commented 10 months ago

Thanks for reporting this, fixed in https://github.com/pytest-dev/pytest-bdd/pull/666