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