python - How to mock out a function that's returned from getattr? -
i have class like:
class myclass(object): def __init__(self, delegate_to): self._delegate_to = delegate_to def __getattr__(self, item): return getattr(self._delegate_to, item) but when try like:
my_mock = self.mox.createmock(myclass) my_mock.f().andreturn(none) mox errors with:
unknownmethodcallerror: method called not member of object: f how mock out delegated calls?
hacky, try:
class mymock(myclass): def f(): pass then in test:
my_mock = self.mox.createmock(mymock) my_mock.f().andreturn(none)
Comments
Post a Comment