我有一个类似于:
的类class MyClass(object):
def __init__(self, delegate_to):
self._delegate_to = delegate_to
def __getattr__(self, item):
return getattr(self._delegate_to, item)
但是当我尝试做类似的事情时:
my_mock = self.mox.CreateMock(MyClass)
my_mock.f().AndReturn(None)
mox错误:
UnknownMethodCallError: Method called is not a member of the object: f
如何模拟委派的电话?
答案 0 :(得分:2)
Hacky,但请尝试:
class MyMock(MyClass):
def f():
pass
然后在测试中:
my_mock = self.mox.CreateMock(MyMock)
my_mock.f().AndReturn(None)