napari_plugin_engine/_testsupport.py
def temporary_hookimpl(test_plugin_manager):
    """A fixture that can be used to insert a HookImplementation in the hook call loop.

    Use as a context manager, which will return the hook_caller for the
    corresponding hook specification.

    Example
    -------
    .. code-block: python

        def my_hook_implementation(arg):
            raise ValueError("shoot!")

        with temporary_hookimpl(my_hook_implementation) as hook_caller:
            with pytest.raises(PluginCallError):
                hook_caller(arg=42)
    """

    @contextmanager
    def wrap(func, specname=None, *, tryfirst=True, trylast=None):
        project = test_plugin_manager.project_name
        marker = HookImplementationMarker(project)
        marker(tryfirst=tryfirst, trylast=trylast, specname=specname)(func)
        _specname = specname or func.__name__
        hook_caller = getattr(test_plugin_manager.hook, _specname, None)
        assert hook_caller, f"No hook with with name: {_specname}"
        opts = getattr(func, HookImplementation.format_tag(project))
        impl = HookImplementation(func, **opts)
        hook_caller._add_hookimpl(impl)
        try:
            yield hook_caller
        finally:
            if impl in hook_caller._nonwrappers:
                hook_caller._nonwrappers.remove(impl)
            if impl in hook_caller._wrappers:
                hook_caller._wrappers.remove(impl)
            assert impl not in hook_caller.get_hookimpls()

    return wrap
A fixture that can be used to insert a HookImplementation in the hook call loop.

    Use as a context manager, which will return the hook_caller for the
    corresponding hook specification.

    Example
    -------
    .. code-block: python

        def my_hook_implementation(arg):
            raise ValueError("shoot!")

        with temporary_hookimpl(my_hook_implementation) as hook_caller:
            with pytest.raises(PluginCallError):
                hook_caller(arg=42)
    
A fixture that can be used to insert a HookImplementation in the hook call loop.
Use as a context manager, which will return the hook_caller for the
corresponding hook specification.

Example

code-block: python




A fixture that can be used to insert a HookImplementation in the hook call loop . Use as a context manager which will return the hook_caller for the corresponding hook specification . Example code - block : python
def temporary_hookimpl(test_plugin_manager):
    @contextmanager
    def wrap(func, specname=None, *, tryfirst=True, trylast=None):
        project = test_plugin_manager.project_name
        marker = HookImplementationMarker(project)
        marker(tryfirst=tryfirst, trylast=trylast, specname=specname)(func)
        _specname = specname or func.__name__
        hook_caller = getattr(test_plugin_manager.hook, _specname, None)
        assert hook_caller, f"No hook with with name: {_specname}"
        opts = getattr(func, HookImplementation.format_tag(project))
        impl = HookImplementation(func, **opts)
        hook_caller._add_hookimpl(impl)
        try:
            yield hook_caller
        finally:
            if impl in hook_caller._nonwrappers:
                hook_caller._nonwrappers.remove(impl)
            if impl in hook_caller._wrappers:
                hook_caller._wrappers.remove(impl)
            assert impl not in hook_caller.get_hookimpls()
    return wrap
def temporary_hookimpl ( test_plugin_manager ) : @ contextmanager def wrap ( func , specname = None , * , tryfirst = True , trylast = None ) : project = test_plugin_manager . project_name marker = HookImplementationMarker ( project ) marker ( tryfirst = tryfirst , trylast = trylast , specname = specname ) ( func ) _specname = specname or func . __name__ hook_caller = getattr ( test_plugin_manager . hook , _specname , None ) assert hook_caller , f"No hook with with name: {_specname}" opts = getattr ( func , HookImplementation . format_tag ( project ) ) impl = HookImplementation ( func , ** opts ) hook_caller . _add_hookimpl ( impl ) try : yield hook_caller finally : if impl in hook_caller . _nonwrappers : hook_caller . _nonwrappers . remove ( impl ) if impl in hook_caller . _wrappers : hook_caller . _wrappers . remove ( impl ) assert impl not in hook_caller . get_hookimpls ( ) return wrap
A fixture that can be used to insert a HookImplementation in the hook call loop.
A fixture that can be used to insert a HookImplementation in the hook call loop .
"""A fixture that can be used to insert a HookImplementation in the hook call loop.

    Use as a context manager, which will return the hook_caller for the
    corresponding hook specification.

    Example
    -------
    .. code-block: python

        def my_hook_implementation(arg):
            raise ValueError("shoot!")

        with temporary_hookimpl(my_hook_implementation) as hook_caller:
            with pytest.raises(PluginCallError):
                hook_caller(arg=42)
    """
test_plugin_manager