[TIP] [mock] Mocking referenced methods?
tom at recursivedream.com
Mon Oct 3 12:14:30 PDT 2011
First off, sorry for the vague term "referenced methods"; I don't know the
proper term for this. Basically, I cannot seem to mock a class method by
name if it is being called as a reference from another attribute. If that
still makes no sense, here's an example:
STUFF = ((meth, True),)
for m, r in self.STUFF:
assert m(self) == r
f = Foo()
with mock.patch.object(f, 'meth') as meth:
with mock.patch('__main__.Foo.meth') as meth:
This example is a bit contrived, but should get the point across. I believe
I understand why the former doesn't work (I need to explicitly call "meth"
with "self", thus it isn't an instance attribute), but I don't understand
why the latter doesn't work, either...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python