From 196229b08d50737f09a646a3e0f644f74e4d1046 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 12 Nov 2017 12:49:12 -0500 Subject: [PATCH] Prove that `PluginManger.register()` ignores non-routines This proves that #91 is a problem in `pytest` and not `pluggy`. Thanks to @RonnyPfannschmidt for the fix about a year ago ;) --- testing/test_pluginmanager.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 7e9701b3..aa0af3bd 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -1,4 +1,5 @@ import pytest +import types from pluggy import (PluginValidationError, HookCallError, HookimplMarker, HookspecMarker) @@ -350,3 +351,24 @@ def m(self, __multicall__, x): def test_add_hookspecs_nohooks(pm): with pytest.raises(ValueError): pm.add_hookspecs(10) + + +def test_reject_prefixed_module(pm): + """Verify that a module type attribute that contains the project + prefix in its name (in this case `'example_*'` isn't collected + when registering a module which imports it. + """ + pm._implprefix = 'example' + conftest = types.ModuleType("conftest") + src = (""" +def example_hook(): + pass +""") + exec(src, conftest.__dict__) + conftest.example_blah = types.ModuleType("example_blah") + name = pm.register(conftest) + assert name == 'conftest' + assert getattr(pm.hook, 'example_blah', None) is None + assert getattr(pm.hook, 'example_hook', None) # conftest.example_hook should be collected + assert pm.parse_hookimpl_opts(conftest, 'example_blah') is None + assert pm.parse_hookimpl_opts(conftest, 'example_hook') == {}