Skip to content

Commit 292488d

Browse files
committed
mh_fixture: make it work with pytest-8.4.0
pytest-8.4.0 removed the __pytest_wrapped__ atribute on a fixture object, instead of unwrapping the object, it now keeps __wrapped__ that we can use instead. This commit makes sure we can work with both old and new pytest. See: pytest-dev/pytest#12473
1 parent 92163c9 commit 292488d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pytest_mh/_private/plugin.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -987,9 +987,17 @@ def wrapper_yield(mh: MultihostFixture, *args, **kwargs):
987987
partial_parameters.extend(
988988
[param for key, param in full_sig.parameters.items() if key != "mh" and key not in mh_args]
989989
)
990-
fixture.__pytest_wrapped__.obj.func.__signature__ = inspect.Signature(
991-
partial_parameters, return_annotation=full_sig.return_annotation
992-
)
990+
991+
if hasattr(fixture, "__pytest_wrapped__"):
992+
obj = fixture.__pytest_wrapped__.obj
993+
elif hasattr(fixture, "__wrapped__"):
994+
obj = fixture.__wrapped__
995+
else:
996+
raise AttributeError(
997+
"Fixture object has no __pytest_wrapped__ nor __wrapped__ attribute, report this to pytest-mh upstream."
998+
)
999+
1000+
obj.func.__signature__ = inspect.Signature(partial_parameters, return_annotation=full_sig.return_annotation)
9931001

9941002
return fixture
9951003

0 commit comments

Comments
 (0)