Skip to content

Commit b29e295

Browse files
committed
Fix failing staticmethod tests if they are inherited
1 parent 7751904 commit b29e295

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Andy Freeland
2929
Anthon van der Neut
3030
Anthony Shaw
3131
Anthony Sottile
32+
Anton Grinevich
3233
Anton Lodder
3334
Antony Lee
3435
Arel Cordero

changelog/8061.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed failing staticmethod test cases if they are inherited from a parent test class.

src/_pytest/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def getfuncargnames(
162162
# it's passed as an unbound method or function, remove the first
163163
# parameter name.
164164
if is_method or (
165-
cls and not isinstance(cls.__dict__.get(name, None), staticmethod)
165+
cls and not isinstance(inspect.getattr_static(cls, name), staticmethod)
166166
):
167167
arg_names = arg_names[1:]
168168
# Remove any names that will be replaced with mocks.

testing/python/fixtures.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ def static(arg1, arg2, x=1):
5959
assert getfuncargnames(A.static, cls=A) == ("arg1", "arg2")
6060

6161

62+
def test_getfuncargnames_staticmethod_inherited() -> None:
63+
"""Test getfuncargnames for inherited staticmethods (#8061)"""
64+
65+
class A:
66+
@staticmethod
67+
def static(arg1, arg2, x=1):
68+
raise NotImplementedError()
69+
70+
class B(A):
71+
pass
72+
73+
assert getfuncargnames(B.static, cls=B) == ("arg1", "arg2")
74+
75+
6276
def test_getfuncargnames_partial():
6377
"""Check getfuncargnames for methods defined with functools.partial (#5701)"""
6478
import functools

0 commit comments

Comments
 (0)