# 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不是个函数:

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

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

inspect.getargspec(fn.__call__)

相关文章:

  • 2021-12-08
  • 2021-09-15
  • 2022-02-19
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-08-30
猜你喜欢
  • 2022-12-23
  • 2022-01-13
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
相关资源
相似解决方案