Skip to content
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

multi hook registration does not unregister #431

Open
RonnyPfannschmidt opened this issue Aug 14, 2023 · 6 comments
Open

multi hook registration does not unregister #431

RonnyPfannschmidt opened this issue Aug 14, 2023 · 6 comments
Labels

Comments

@RonnyPfannschmidt
Copy link
Member

#251 added having multiple hooks of the same name to a plugin

https://github.com/pytest-dev/pluggy/blob/475c4aa99200bfa3e30d12458ab2a3593a36dd56/src/pluggy/_hooks.py#L417-L422C57 does not unregister them

@wahuneke
Copy link
Contributor

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 ...

@RonnyPfannschmidt
Copy link
Member Author

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

@wahuneke
Copy link
Contributor

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).

@wahuneke
Copy link
Contributor

@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

@RonnyPfannschmidt
Copy link
Member Author

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

@wahuneke
Copy link
Contributor

wahuneke commented Sep 22, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants