-
-
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
Parent class marked fixture no longer reached with pytest 7.2 #10447
Comments
To be sure, these tests deserve a refactor. The tests are in this state because the project is transitioning away from unittest, but some artifacts remain. |
Probably |
this may be related to extraction of marks from the mro, (dint happenbefore, was aded recently |
The MRO refactor was #7792 (31df38f). I've confirmed that the distutils fail on 31df38f but pass on 31df38f^1, confirming that change is the culprit. The changelog says:
That implies that it's intentional that previously reachable marks are now intentionally ignored. I'm not sure why that wouldn't be a breaking change. Is there any chance pytest will restore support for this use-case? Is there a way to apply a fixture at a superclass and have it take effect in a subclass? |
The markers should take effect as all of them should land in the node for the class, I'll have to investigate the order difference |
In that case, let me put together a more minimal repro. |
Good news. A minimal repro was easy and I learned something: draft @ cat test_something.py
import pytest
@pytest.fixture
def add_attr1(request):
request.instance.attr1 = object()
@pytest.fixture
def add_attr2(request):
request.instance.attr2 = request.instance.attr1
@pytest.mark.usefixtures('add_attr1')
class Parent:
pass
@pytest.mark.usefixtures('add_attr2')
class TestThings(Parent):
def test_attrs(self):
self.attr1
self.attr2
The issue isn't that the fixture on the parent class isn't being called, but that the fixtures are called in a different order with the fixture on the child being called before the fixture on the parent. Independent of this specific example, I'd expect fixtures on more basic classes to be called first, as the child (derived) class is liable to depend on behavior from the parent but not vice-versa (from a modeling perspective, the parent class is largely unaware of the child classes). |
Found the bug https://github.com/pytest-dev/pytest/blob/main/src/_pytest/mark/structures.py#L377 is missing a reversed when considering the mro |
…se classes priority
…se classes priority
@jaraco seems like our timing was unfortuate |
No problem. Happy to consolidate. I'll fix the mypy bug in mine and copy the test from yours, but feel free to choose the PR you prefer. |
@jaraco im under the impression that the content would practically be the same, so i'd just go with mine |
…order-needs-reverse fix #10447 - consider marks in reverse mro order to give base classes priority
Starting with the release of pytest 7.2, the distutils tests started failing (pypa/distutils#186).
I read the changelog for 7.2, but I don't see anything relevant.
The issue is likely due to some of these factors:
usefixtures
See the upstream bug for:
pip list
from the virtual environment you are usingFor consideration:
I haven't put together a minimal example yet as I'm still triaging the issue. Is there a known change with pytest 7.2 that was expected to change this behavior?
The text was updated successfully, but these errors were encountered: