Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest-bdd doesn't support pytest 8.1.0 #674

Closed
DevKeravi opened this issue Mar 4, 2024 · 5 comments
Closed

pytest-bdd doesn't support pytest 8.1.0 #674

DevKeravi opened this issue Mar 4, 2024 · 5 comments

Comments

@DevKeravi
Copy link

DevKeravi commented Mar 4, 2024

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/[email protected]/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/[email protected]/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
Copy link
Author

DevKeravi commented Mar 4, 2024

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
Copy link
Author

DevKeravi commented Mar 4, 2024

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,
    )

@DevKeravi DevKeravi reopened this Mar 4, 2024
@The-Compiler
Copy link
Member

As you say, this is already fixed, only a release is missing (which should happen today: #666 (comment))

@youtux
Copy link
Contributor

youtux commented Mar 4, 2024

pytest-bdd 7.1.1 is out

@youtux youtux closed this as completed Mar 4, 2024
@DevKeravi
Copy link
Author

@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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants