Skip to content

Prove that PluginManger.register() ignores non-routines #97

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
import types

from pluggy import (PluginValidationError,
HookCallError, HookimplMarker, HookspecMarker)
Expand Down Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For completeness, I would add an example_ function to one of the modules and ensure that it is collected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Heh, and found a bug from the _Multicall refactor.. shocker we've got no tests for the undecorated hook collection stuff.

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') == {}