Skip to content

Commit 76816a8

Browse files
committed
use callable classes instead of function for funcopy
1 parent 816a404 commit 76816a8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/unittest/mock.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,13 @@ def checksig(*args, **kwargs):
199199
if not name.isidentifier():
200200
name = 'funcopy'
201201
context = {'_checksig_': checksig, 'mock': mock}
202-
src = """def %s(*args, **kwargs):
203-
_checksig_(*args, **kwargs)
204-
return mock(*args, **kwargs)""" % name
202+
src = """class %s:
203+
def __call__(*args, **kwargs):
204+
_checksig_(*args, **kwargs)
205+
return mock(*args, **kwargs)
206+
def call_count(self):
207+
return len(self.call_args_list)
208+
%s = %s()""" % name
205209
exec (src, context)
206210
funcopy = context[name]
207211
_setup_func(funcopy, mock, sig)

0 commit comments

Comments
 (0)