First off, sorry for the vague term &quot;referenced methods&quot;; I don&#39;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&#39;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, &#39;meth&#39;) 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(&#39;__main__.Foo.meth&#39;) 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&#39;t work (I need to explicitly call &quot;meth&quot; with &quot;self&quot;, thus it isn&#39;t an instance attribute), but I don&#39;t understand why the latter doesn&#39;t work, either...</div>