温温酱
Python: 测试函数是否被调用# helper class defined elsewhereclass CallLogger(object):def __init__(self, meth):self.meth = methself.was_called = Falsedef __call__(self, code=None):self.meth()self.was_called = True然后assert CallLogger的was_called为True就行了。但是这样的Callable不是个函数:isinstance(object, types.FunctionType) # Callable will be False对于这种Callable获取参数个数需要用:inspect.getargspec(fn.__call__)