pytest-dev/pluggy

multi hook registration does not unregister

RonnyPfannschmidt opened this issue · 6 comments

Hi @RonnyPfannschmidt . I added the following test case in test_hookcaller.py but this did not result in test failure. Am I misunderstanding the (brief) description on this bug?

def test_hook_multi_impl(pm: PluginManager) -> None:
    """Since plugins' impls are able to (optionally) specify a spec name, it is possible for a plugin to implement
    the same spec multiple times."""

    class Api:
        @hookspec
        def hello(self, arg: object) -> None:
            "api hook 1"

    pm.add_hookspecs(Api)
    hook = pm.hook

    class Plugin:
        @hookimpl
        def hello(self, arg):
            return arg + 1

        @hookimpl(specname="hello")
        def hello_again(self, arg):
            return arg + 100

    plugin = Plugin()
    pm.register(plugin)
    out = hook.hello(arg=3)
    assert out == [103, 4]
    pm.unregister(plugin)
    assert hook.hello(arg=3) == []

I'm new to this project and hoping to help out somewhere. This looked like a spot to jump in ...

Please validate both hooks are actually registered,I believe there's a second issue at Hand

Ok. I will compare your feedback to the code and see what else I can check in order to confirm that both implementations are actually registered.

The test case does already confirm that:

  • both implementations get run by the hook caller
  • and, confirms that neither implementations remain after we deregister

I will take a look to see what other aspects I can confirm (perhaps something in tracing or other utils).

@RonnyPfannschmidt - I've added additional testing but still do not see any test failures.

I've added:

  • checks of other methods on the plugin manager and the hook caller, confirming sane results
  • a simple test for tracing, both for standard plugin usage and for this special case plugin

Rather than paste new code here for you to look at, I've created a Draft PR #446

PS, I finally figured why it's working,

Unregister collects hook callers for plugins multiple times if there's multiple registration, thus in turn unregister is called multiple times