How to use the pluggy.PluginValidationError function in pluggy

To help you get started, we’ve selected a few pluggy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytest-dev / pluggy / testing / test_hookcaller.py View on Github external
        @hookimpl(specname="hello")
        def foo(self, arg, too, many, args):
            return arg + 1

    with pytest.raises(PluginValidationError):
        pm.register(Plugin())

    # make sure check_pending still fails if specname doesn't have a
    # corresponding spec.  EVEN if the function name matches one.
    class Plugin2:
        @hookimpl(specname="bar")
        def hello(self, arg):
            return arg + 1

    pm.register(Plugin2())
    with pytest.raises(PluginValidationError):
        pm.check_pending()
github pytest-dev / pluggy / testing / test_pluggy.py View on Github external
def test_register_mismatch_method(self, he_pm):
        class hello:
            @hookimpl
            def he_method_notexists(self):
                pass

        he_pm.register(hello())
        with pytest.raises(PluginValidationError):
            he_pm.check_pending()
github pytest-dev / pluggy / testing / test_pluginmanager.py View on Github external
def test_register_mismatch_method(he_pm):
    class hello:
        @hookimpl
        def he_method_notexists(self):
            pass

    plugin = hello()

    he_pm.register(plugin)
    with pytest.raises(PluginValidationError) as excinfo:
        he_pm.check_pending()
    assert excinfo.value.plugin is plugin
github pytest-dev / pluggy / testing / test_pluggy.py View on Github external
def test_register_mismatch_arg(self, he_pm):
        class hello:
            @hookimpl
            def he_method1(self, qlwkje):
                pass

        with pytest.raises(PluginValidationError):
            he_pm.register(hello())
github pytest-dev / pluggy / testing / test_invocations.py View on Github external
def test_argmismatch(pm):
    class Api:
        @hookspec
        def hello(self, arg):
            "api hook 1"

    pm.add_hookspecs(Api)

    class Plugin:
        @hookimpl
        def hello(self, argwrong):
            pass

    with pytest.raises(PluginValidationError) as exc:
        pm.register(Plugin())

    assert "argwrong" in str(exc.value)
github web-platform-tests / wpt / tools / third_party / pluggy / testing / test_hookrelay.py View on Github external
def test_argmismatch(pm):
    class Api(object):
        @hookspec
        def hello(self, arg):
            "api hook 1"

    pm.add_hookspecs(Api)

    class Plugin(object):
        @hookimpl
        def hello(self, argwrong):
            pass

    with pytest.raises(PluginValidationError) as exc:
        pm.register(Plugin())

    assert "argwrong" in str(exc.value)
github pytest-dev / pluggy / testing / test_hookcaller.py View on Github external
would have without using specname."""

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

    pm.add_hookspecs(Api)

    # make sure a bad signature still raises an error when using specname
    class Plugin:
        @hookimpl(specname="hello")
        def foo(self, arg, too, many, args):
            return arg + 1

    with pytest.raises(PluginValidationError):
        pm.register(Plugin())

    # make sure check_pending still fails if specname doesn't have a
    # corresponding spec.  EVEN if the function name matches one.
    class Plugin2:
        @hookimpl(specname="bar")
        def hello(self, arg):
            return arg + 1

    pm.register(Plugin2())
    with pytest.raises(PluginValidationError):
        pm.check_pending()
github pytest-dev / pluggy / testing / test_pluginmanager.py View on Github external
def test_register_historic_incompat_hookwrapper(pm):
    class Hooks:
        @hookspec(historic=True)
        def he_method1(self, arg):
            pass

    pm.add_hookspecs(Hooks)

    out = []

    class Plugin:
        @hookimpl(hookwrapper=True)
        def he_method1(self, arg):
            out.append(arg)

    with pytest.raises(PluginValidationError):
        pm.register(Plugin())
github flaskbb / flaskbb / flaskbb / plugins / manager.py View on Github external
"""Load modules from querying the specified setuptools entrypoint name.
        Return the number of loaded plugins. """
        logger.info("Loading plugins under entrypoint {}"
                    .format(entrypoint_name))
        for ep in iter_entry_points(entrypoint_name):
            if self.get_plugin(ep.name):
                continue

            try:
                plugin = ep.load()
            except DistributionNotFound:
                logger.warn("Could not load plugin {}. Passing."
                            .format(ep.name))
                continue
            except VersionConflict as e:
                raise pluggy.PluginValidationError(
                    "Plugin %r could not be loaded: %s!" % (ep.name, e)
                )

            if self.is_blocked(ep.name):
                self._disabled_plugins[plugin] = (ep.name, ep.dist)
                self._plugin_metadata[ep.name] = \
                    parse_pkg_metadata(ep.dist.key)
                continue

            self.register(plugin, name=ep.name)
            self._plugin_distinfo.append((plugin, ep.dist))
            self._plugin_metadata[ep.name] = parse_pkg_metadata(ep.dist.key)
            logger.info("Loaded plugin: {}".format(ep.name))
        logger.info("Loaded {} plugins for entrypoint {}".format(
            len(self._plugin_distinfo),
            entrypoint_name