pytest-dev / pytest-bdd

BDD library for the py.test runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.3k stars 219 forks source link

pytest-bdd doesn't support pytest 8.1.0 #674

Closed DevKeravi closed 6 months ago

DevKeravi commented 7 months ago

pytest-dev/pytest#12069

Today pytest has been updated version 8.1.0 they update this thing

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.

I update my pytest version to 8.1.0, pytest-bdd couldn't find this removed method so I getting this errors,

ImportError: cannot import name 'iterparentnodeids' from '_pytest.nodes'

now iterparentnodeids function has been removed, but it can traverse the node hierarchy itself so why don't we change that code?

this is my full error logs


    config = pluginmanager.hook.pytest_cmdline_parse(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/pluggy/_hooks.py", line 501, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/pluggy/_manager.py", line 119, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/pluggy/_callers.py", line 138, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/pluggy/_callers.py", line 121, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/_pytest/helpconfig.py", line 105, in pytest_cmdline_parse
    config = yield
             ^^^^^
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/pluggy/_callers.py", line 102, in _multicall
    res = hook_impl.function(*args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1141, in pytest_cmdline_parse
    self.parse(args)
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1490, in parse
    self._preparse(args, addopts=addopts)
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/_pytest/config/__init__.py", line 1377, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/pluggy/_manager.py", line 414, in load_setuptools_entrypoints
    plugin = ep.load()
             ^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/metadata/__init__.py", line 202, in load
    module = import_module(match.group('module'))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1126, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 178, in exec_module
    exec(co, module.__dict__)
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/pytest_bdd/__init__.py", line 4, in <module>
    from pytest_bdd.scenario import scenario, scenarios
  File "/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/_pytest/assertion/rewrite.py", line 178, in exec_module
    exec(co, module.__dict__)
  File "/Users/demian/workspace/venv-dealmatch/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' (/Users/demian/workspace/venv-dealmatch/lib/python3.11/site-packages/_pytest/nodes.py)```
DevKeravi commented 7 months ago

I found this commit for pytest 8.1 version

that is only option for this problem?

The signature of this (private) function will change in the upcoming
pytest 8.1 release:
https://github.com/pytest-dev/pytest/pull/11785

Additionally, the `iterparentnodeids` function is removed, so
copy/pasting it for now.

I verified that all tests pass when run against pytest main.
DevKeravi commented 7 months ago

I fork master branch and that commit working that issue, but I found more issue that pytest's FixtureDef Class initializer doesn't take fixturemanager no longer,

this is removed commit 2 month ago

fixtures: avoid FixtureDef <-> FixtureManager reference cycle
There is no need to store the FixtureManager on each FixtureDef.

and I found this in code.

this is in _pytest/fixture.py 960 line, FixtureDef init code

    def __init__(
        self,
        config: Config,
        baseid: Optional[str],
        argname: str,
        func: "_FixtureFunc[FixtureValue]",
        scope: Union[Scope, _ScopeName, Callable[[str, Config], _ScopeName], None],
        params: Optional[Sequence[object]],
        unittest: bool = False,
        ids: Optional[
            Union[Tuple[Optional[object], ...], Callable[[Any], Optional[object]]]
        ] = None,
        *,
        _ispytest: bool = False,
    ) -> None:

this is pytest-bdd/steps.py line 212 FixtureDef initialize code

def inject_fixture(request: FixtureRequest, arg: str, value: Any) -> None:
    """Inject fixture into pytest fixture request.

    :param request: pytest fixture request
    :param arg: argument name
    :param value: argument value
    """

    fd = FixtureDef(
        fixturemanager=request._fixturemanager,
        baseid=None,
        argname=arg,
        func=lambda: value,
        scope="function",
        params=None,
    )
The-Compiler commented 6 months ago

As you say, this is already fixed, only a release is missing (which should happen today: https://github.com/pytest-dev/pytest-bdd/pull/666#issuecomment-1975908677)

youtux commented 6 months ago

pytest-bdd 7.1.1 is out

DevKeravi commented 6 months ago

@youtux I read your comment and I upgrade pytest-bdd version but pytest yanked there version 8.1.0 to 8.0.3 cause so many plugin crashed thanks for answer and have a nice day :)