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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -