<div id="geary-body" dir="auto"><div><br></div></div><div id="geary-quote" dir="auto"><br>On Wed, Jan 4 2023 at 09:26:10 AM +00:00:00, Sofia Enriquez <senrique@redhat.com> wrote:<br><blockquote type="cite"><div dir="ltr"><div>Hi,</div><div><br></div><div>Since python3.11 mocks can no longer be provided as the specs for other Mocks. As a
result, an already-mocked object cannot be passed to mock.Mock(). This
can uncover bugs in tests since these Mock-derived Mocks will always
pass certain tests (e.g. isinstance) and built-in assert functions (e.g.
assert_called_once_with) will unconditionally pass.[1]</div><div><br></div>There's a bug report to track this issue in Cinder [2] but I think this may affect other projects too. <br><div><br></div><div>I've reproduce the error and most drivers fail with:</div><div>```<br></div><div>unittest.mock.InvalidSpecError: Cannot spec a Mock object. [object=<Mock name='mock.client.HPE3ParClient' id='139657768087760'>]</div><div><div>```</div><div><br></div></div></div></blockquote><div><br></div><div>Nova went through this and removed double mocking during Zed. Here are the patches: https://review.opendev.org/q/topic:unittest.mock+%2522double+mocking%2522 Maybe you can use it for ideas how to deal with different double mocking scenarios: <br> </div><div>Cheers,</div><div>gibi</div><div><br><blockquote type="cite"><div dir="ltr"><div><div>Cheers,</div><div>Sofia</div><div><br></div><div>[1] <a href="https://github.com/python/cpython/issues/87644">https://github.com/python/cpython/issues/87644</a></div><div>[2] <a href="https://bugs.launchpad.net/cinder/+bug/2000436">https://bugs.launchpad.net/cinder/+bug/2000436</a></div><div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div>
<p style="font-weight:bold;margin:0px;padding:0px;font-size:14px;text-transform:capitalize;font-family:"RedHatText",sans-serif">
<font size="1"><span>Sofía</span> <span>Enriquez</span><span style="color:rgb(170,170,170);margin:0px"></span>
</font></p><font size="1">
</font><p style="font-weight:normal;margin:0px 0px 4px;text-transform:capitalize;font-family:"RedHatText",sans-serif"><font size="1">she/her</font></p><font size="1">
</font><p style="font-weight:normal;margin:0px;text-transform:capitalize;font-family:"RedHatText",sans-serif">
<font size="1"><span>Software Engineer</span></font>
</p><font size="1">
</font><p style="font-weight:normal;margin:0px 0px 4px;font-family:"RedHatText",sans-serif">
<font size="1"><a style="color:rgb(0,136,206);margin:0px;text-decoration:none;font-family:"RedHatText",sans-serif" href="https://www.redhat.com" target="_blank">Red Hat <span>PnT</span></a></font>
</p><font size="1"><span></span></font><p style="font-weight:normal;margin:0px;font-family:"RedHatText",sans-serif"><font size="1"><span><span>IRC: @enriquetaso</span></span></font>
</p><font size="1">
</font><div style="font-weight:normal;font-size:12px;font-family:"RedHatText",sans-serif;margin-bottom:8px"><font size="1">
</font><div><font size="1">
<a href="https://twitter.com/redhat" title="twitter" style="background:transparent url("https://marketing-outfit-prod-images.s3-us-west-2.amazonaws.com/3780bd4ede961ef3cd4108b8c0e80186/web-icon-twitter.png") no-repeat scroll 0px 50%/13px auto;text-decoration:none;color:rgb(0,0,0);display:inline-block;line-height:20px;padding-left:13px" target="_blank"> <span style="margin-left:2px">@RedHat</span> </a> <a href="https://www.linkedin.com/company/red-hat" title="LinkedIn" style="background:transparent url("https://marketing-outfit-prod-images.s3-us-west-2.amazonaws.com/8d3507e3c6b6c9ad10e301accf1a4af0/web-icon-linkedin.png") no-repeat scroll 0px 50%/12px auto;text-decoration:none;color:rgb(0,0,0);display:inline-block;line-height:20px;padding-left:12px;margin:0px 4px 0px 3px;padding-top:1px" target="_blank"> <span style="margin-left:4px">Red Hat</span> </a> </font><a href="https://www.facebook.com/RedHatInc" title="Facebook" style="background:transparent url("https://marketing-outfit-prod-images.s3-us-west-2.amazonaws.com/220b85e2f100025e94cb1bcd993bd51d/web-icon-facebook.png") no-repeat scroll 0px 50%/11px auto;text-decoration:none;color:rgb(0,0,0);display:inline-block;line-height:20px;padding-left:13px" target="_blank"><font size="1"> <span>Red Hat</span></font> </a>
</div>
</div>
<div style="margin-top:12px">
<table border="0">
<tbody><tr>
<td width="100px"><a href="https://www.redhat.com" target="_blank"> <img src="https://marketing-outfit-prod-images.s3-us-west-2.amazonaws.com/f5445ae0c9ddafd5b2f1836854d7416a/Logo-RedHat-Email.png" width="90" height="auto"></a> </td>
</tr>
</tbody></table>
</div>
</div><table border="0"><tbody><tr><td width="100px"><br></td>
</tr></tbody></table>
</div></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div></div>