Skip to content

Commit 607862c

Browse files
author
goodboy
authored
Merge pull request #97 from tgoodlet/test_reject_non_routine_hookimpls
Prove that `PluginManger.register()` ignores non-routines
2 parents 01d3589 + 8ce9161 commit 607862c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

testing/test_pluginmanager.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
import types
23

34
from pluggy import (PluginValidationError,
45
HookCallError, HookimplMarker, HookspecMarker)
@@ -350,3 +351,24 @@ def m(self, __multicall__, x):
350351
def test_add_hookspecs_nohooks(pm):
351352
with pytest.raises(ValueError):
352353
pm.add_hookspecs(10)
354+
355+
356+
def test_reject_prefixed_module(pm):
357+
"""Verify that a module type attribute that contains the project
358+
prefix in its name (in this case `'example_*'` isn't collected
359+
when registering a module which imports it.
360+
"""
361+
pm._implprefix = 'example'
362+
conftest = types.ModuleType("conftest")
363+
src = ("""
364+
def example_hook():
365+
pass
366+
""")
367+
exec(src, conftest.__dict__)
368+
conftest.example_blah = types.ModuleType("example_blah")
369+
name = pm.register(conftest)
370+
assert name == 'conftest'
371+
assert getattr(pm.hook, 'example_blah', None) is None
372+
assert getattr(pm.hook, 'example_hook', None) # conftest.example_hook should be collected
373+
assert pm.parse_hookimpl_opts(conftest, 'example_blah') is None
374+
assert pm.parse_hookimpl_opts(conftest, 'example_hook') == {}

0 commit comments

Comments
 (0)