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:<div>
<br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div><div>import mock</div></div><div><div><br></div></div><div><div><br></div></div><div><div>class Foo(object):</div>
</div><div><div> def meth(self):</div></div><div><div> return True</div></div><div><div><br></div></div><div><div> STUFF = ((meth, True),)</div></div><div><div><br></div></div><div><div> def do(self):</div>
</div><div><div> for m, r in self.STUFF:</div></div><div><div> assert m(self) == r</div></div><div><div> </div></div><div><div>f = Foo()</div></div><div><div><br></div></div><div><div>f.do()</div></div>
<div><div><br></div></div><div><div>with mock.patch.object(f, 'meth') as meth:</div></div><div><div> f.do()</div></div><div><div> assert meth.called</div></div><div><div><br></div></div><div><div>with mock.patch('__main__.Foo.meth') as meth:</div>
</div><div><div> f.do()</div></div><div><div> assert meth.called</div></div></blockquote><div><div><br></div></div><div>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...</div>