@@ -80,7 +80,7 @@ def num_mock_patch_args(function):
80
80
)
81
81
82
82
83
- def getfuncargnames (function , is_method = False , cls = None ):
83
+ def getfuncargnames (function , * , name : str = "" , is_method = False , cls = None ):
84
84
"""Returns the names of a function's mandatory arguments.
85
85
86
86
This should return the names of all function arguments that:
@@ -93,11 +93,12 @@ def getfuncargnames(function, is_method=False, cls=None):
93
93
be treated as a bound method even though it's not unless, only in
94
94
the case of cls, the function is a static method.
95
95
96
+ The name parameter should be the original name in which the function was collected.
97
+
96
98
@RonnyPfannschmidt: This function should be refactored when we
97
99
revisit fixtures. The fixture mechanism should ask the node for
98
100
the fixture names, and not try to obtain directly from the
99
101
function object well after collection has occurred.
100
-
101
102
"""
102
103
# The parameters attribute of a Signature object contains an
103
104
# ordered mapping of parameter names to Parameter instances. This
@@ -120,11 +121,14 @@ def getfuncargnames(function, is_method=False, cls=None):
120
121
)
121
122
and p .default is Parameter .empty
122
123
)
124
+ if not name :
125
+ name = function .__name__
126
+
123
127
# If this function should be treated as a bound method even though
124
128
# it's passed as an unbound method or function, remove the first
125
129
# parameter name.
126
130
if is_method or (
127
- cls and not isinstance (cls .__dict__ .get (function . __name__ , None ), staticmethod )
131
+ cls and not isinstance (cls .__dict__ .get (name , None ), staticmethod )
128
132
):
129
133
arg_names = arg_names [1 :]
130
134
# Remove any names that will be replaced with mocks.
@@ -247,7 +251,7 @@ def get_real_method(obj, holder):
247
251
try :
248
252
is_method = hasattr (obj , "__func__" )
249
253
obj = get_real_func (obj )
250
- except Exception :
254
+ except Exception : # pragma: no cover
251
255
return obj
252
256
if is_method and hasattr (obj , "__get__" ) and callable (obj .__get__ ):
253
257
obj = obj .__get__ (holder )
0 commit comments