-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fixtures: match fixtures based on actual node hierarchy, not textual nodeids #11785
Conversation
1531eed
to
29a8bda
Compare
Looking at plugins from my local corpus: Affected by
Affected by
Affected by
I've considered deprecations but since these are private APIs and the fixes are not very difficult, I've decided not to. Instead, I added a changelog entry and will open issues for the projects above if this PR is merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally 🎉🍾🎆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup!
- ``FixtureManager._getautousenames()`` now takes a ``Node`` itself instead of the nodeid. | ||
- ``FixtureManager.getfixturedefs()`` now takes the ``Node`` itself instead of the nodeid. | ||
- The ``_pytest.nodes.iterparentnodeids()`` function is removed without replacement. | ||
Prefer to traverse the node hierarchy itself instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer to traverse the node hierarchy itself instead. | |
Prefer to traverse the node hierarchy itself using ``_pytest.nodes.iterparentnodes()`` instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I now realize that you might not want to advertise the internal function on purpose -- if that's the case feel free to ignore this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I don't mean to expose it. I think it can be nice as a Node
method, maybe later.
…nodeids Refs pytest-dev#11662. --- Problem Each fixture definition has a "visibility", the `FixtureDef.baseid` attribute. This is nodeid-like string. When a certain `node` requests a certain fixture name, we match node's nodeid against the fixture definitions with this name. The matching currently happens on the *textual* representation of the nodeid - we split `node.nodeid` to its "parent nodeids" and then check if the fixture's `baseid` is in there. While this has worked so far, we really should try to avoid textual manipulation of nodeids as much as possible. It has also caused problem in an odd case of a `Package` in the root directory: the `Package` gets nodeid `.`, while a `Module` in it gets nodeid `test_module.py`. And textually, `.` is not a parent of `test_module.py`. --- Solution Avoid this entirely by just checking the node hierarchy itself. This is made possible by the fact that we now have proper `Directory` nodes (`Dir` or `Package`) for the entire hierarchy. Also do the same for `_getautousenames` which is a similar deal. The `iterparentnodeids` function is no longer used and is removed.
bcfc853
to
992d0f0
Compare
Temporarily disabled pytest-bdd plugin check until it's updated |
The signature of this (private) function will change in the upcoming pytest 8.1 release: pytest-dev/pytest#11785 I verified that all tests pass when run against pytest main.
The signature of this (private) function will change in the upcoming pytest 8.1 release: pytest-dev/pytest#11785 Additionally, the `iterparentnodeids` function is removed, so copy/pasting it for now. I verified that all tests pass when run against pytest main.
The signature of this (private) function will change in the upcoming pytest 8.1 release: pytest-dev/pytest#11785
The signature of this (private) function will change in the upcoming pytest 8.1 release: pytest-dev/pytest#11785
The signature of this (private) function will change in the upcoming pytest 8.1 release: pytest-dev/pytest#11785
The signature of this (private) function will change in the upcoming pytest 8.1 release: pytest-dev/pytest#11785
The signature of this (private) function will change in the upcoming pytest 8.1 release: pytest-dev/pytest#11785
Refs #11662.
Problem
Each fixture definition has a "visibility", the
FixtureDef.baseid
attribute. This is nodeid-like string. When a certainnode
requests a certain fixture name, we match node's nodeid against the fixture definitions with this name.The matching currently happens on the textual representation of the nodeid - we split
node.nodeid
to its "parent nodeids" and then check if the fixture'sbaseid
is in there.While this has worked so far, we really should try to avoid textual manipulation of nodeids as much as possible. It has also caused problem in an odd case of a
Package
in the root directory: thePackage
gets nodeid.
, while aModule
in it gets nodeidtest_module.py
. And textually,.
is not a parent oftest_module.py
.Solution
Avoid this entirely by just checking the node hierarchy itself. This is made possible by the fact that we now have proper
Directory
nodes (Dir
orPackage
) for the entire hierarchy.Also do the same for
_getautousenames
which is a similar deal.The
iterparentnodeids
function is no longer used and is removed.