pytest-dev / pluggy

A minimalist production ready plugin system
https://pluggy.readthedocs.io/en/latest/
MIT License
1.24k stars 121 forks source link

Issue with ordering of hooks #441

Closed smarie closed 7 months ago

smarie commented 1 year ago

I recently observed a strange issue in pytest-cases in conjunction with a fake hook mimicking pytest-repeat.

Basically, the problem is that a hook with tryfirst=True, wrapper=True gets called after a plugin with trylast=True. See issue description here : https://github.com/smarie/python-pytest-cases/issues/302

Could it be related with these lines ?

https://github.com/pytest-dev/pluggy/blob/136bbe8c98b66cbcefdc2438bf3c59705678249b/src/pluggy/_hooks.py#L542C1-L548C15

            # Find last non-tryfirst nonwrapper method.
            i = len(hookimpls) - 1
            while (
                i >= 0
                and hookimpls[i].tryfirst
                and not (hookimpls[i].hookwrapper or hookimpls[i].wrapper)
            ):

It seems to me that the correct statement in the while is rather

            # Find last non-tryfirst nonwrapper method.
            i = len(hookimpls) - 1
            while (
                i >= 0
                and (hookimpls[i].tryfirst
                or hookimpls[i].hookwrapper or hookimpls[i].wrapper)
            ):

Am I correct ?

RonnyPfannschmidt commented 1 year ago

This seems like the case, let's add some tests for that details

smarie commented 7 months ago

Thanks @bluetech !