Skip to content

Fix getfixturedefs call #12

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

Merged
merged 1 commit into from
Apr 30, 2025
Merged

Conversation

MaksimKravchuk
Copy link
Contributor

@MaksimKravchuk MaksimKravchuk commented Dec 11, 2024

Problem:
Test runs with --show-fixture-duplicates fail with error:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/user/Code/e2e/venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 1771, in _matchfactories
INTERNALERROR>     parentnodeids = {n.nodeid for n in node.iter_parents()}
INTERNALERROR>                                        ^^^^^^^^^^^^^^^^^
INTERNALERROR> AttributeError: 'str' object has no attribute 'iter_parents'
INTERNALERROR> 
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR> 
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/user/Code/e2e/venv/lib/python3.12/site-packages/_pytest/main.py", line 285, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>                          ^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/Users/user/Code/e2e/venv/lib/python3.12/site-packages/pytest_fixture_tools/plugin.py", line 94, in _show_fixture_duplicates_main
INTERNALERROR>     fixturedefs = fm.getfixturedefs(argname, item.nodeid)
INTERNALERROR>                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/Users/user/Code/e2e/venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 1765, in getfixturedefs
INTERNALERROR>     return tuple(self._matchfactories(fixturedefs, node))
INTERNALERROR>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File "/Users/user/Code/e2e/venv/lib/python3.12/site-packages/_pytest/fixtures.py", line 1773, in _matchfactories
INTERNALERROR>     raise ValueError("node must be a Node instance")
INTERNALERROR> ValueError: node must be a Node instance

It happens because getfixturedefs takes a Node object, not a node ID string.
https://github.com/pytest-dev/pytest/blob/949c7711b3e22ab94110f1ae4fc307cda2f9e379/src/_pytest/fixtures.py#L1824

This PR fix the problem.


This change is Reviewable

@MaksimKravchuk
Copy link
Contributor Author

@ogajduse Hey! Please take a look at this PR

@ogajduse
Copy link
Collaborator

It is indeed as you mentioned. The signature of the function is:

def getfixturedefs(
        self, argname: str, node: nodes.Node
    ) -> Sequence[FixtureDef[Any]] | None:

Docs: https://docs.pytest.org/en/8.3.x/_modules/_pytest/fixtures.html

Copy link
Collaborator

@ogajduse ogajduse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it took that long.

@ogajduse ogajduse merged commit cffa7a2 into pytest-dev:master Apr 30, 2025
@ogajduse ogajduse added the bug label Apr 30, 2025
@ogajduse
Copy link
Collaborator

It took me a while, but a new release with your patch is out.
https://pypi.org/project/pytest-fixture-tools/1.2.1/

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

Successfully merging this pull request may close these issues.

2 participants