Skip to content

Commit 8786933

Browse files
author
Tyler Goodlet
committed
Add a test which breaks spec loading
Currently if you instantiate class which defines hook specs the introspector (`pluggy.varnames`) breaks on methods and incorrectly returns the `self` name. I found this by accident. Although it would be odd it's still conceivable that a user might wish to define hook specs on an instance. The real problem seems to be that varnames doesn't actually disregard `self` like the doc string claims.
1 parent ded4c2e commit 8786933

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

testing/test_pluggy.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,23 @@ def pm():
1717
return PluginManager("example")
1818

1919

20-
@pytest.fixture
21-
def he_pm(pm):
20+
@pytest.fixture(
21+
params=[
22+
lambda spec: spec,
23+
lambda spec: spec()
24+
],
25+
ids=[
26+
"don't instantiate",
27+
"instatiate"
28+
],
29+
)
30+
def he_pm(request, pm):
2231
class Hooks:
2332
@hookspec
2433
def he_method1(self, arg):
2534
return arg + 1
2635

27-
pm.add_hookspecs(Hooks)
36+
pm.add_hookspecs(request.param(Hooks))
2837
return pm
2938

3039

@@ -706,8 +715,17 @@ def __init__(self, x):
706715
class D:
707716
pass
708717

718+
class E(object):
719+
def __init__(self, x):
720+
pass
721+
722+
class F(object):
723+
pass
724+
709725
assert varnames(C) == ("x",)
710726
assert varnames(D) == ()
727+
assert varnames(E) == ("x",)
728+
assert varnames(F) == ()
711729

712730

713731
def test_formatdef():

0 commit comments

Comments
 (0)