Python: 测试函数是否被调用

# helper class defined elsewhere
class CallLogger(object):
   def __init__(self, meth):
     self.meth = meth
     self.was_called = False

   def __call__(self, code=None):
     self.meth()
     self.was_called = True

而后assert CallLogger的was_called为True就好了。可是这样的Callable不是个函数:html

isinstance(object, types.FunctionType) # Callable will be False

对于这种Callable获取参数个数须要用:函数

inspect.getargspec(fn.__call__)
相关文章
相关标签/搜索