<div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px">I&#39;ve recently started using the mock library in my code (transitioning from Mox) and I really like it a lot. There&#39;s a few little utilities I&#39;ve written for myself and I wonder if you&#39;d accept them as patches.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">First, I find that I strongly prefer to use autospecced instances for most of my mocks. To make that simpler, I wrote a create_strictspec() function as a wrapper around create_autospec() with instance=True.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">I also find that I frequently want a mock function that should never be called (e.g., in a test where I&#39;m patching open() and testing a code path where no file is opened). This can be asserted ex post by checking call_count, but then you don&#39;t get any information about where the call occurred. Alternatively, you can use a NoncallableMock, but then you get a fairly opaque error: &quot;TypeError: &#39;NonCallableMock&#39; object is not callable&quot;. I find it preferable to use a utility method expect_never_called() to set an AssertionError side effect on the mock.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Do you think these would be helpful additions to the library?</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">Best regards,</div><div style="font-family:arial,sans-serif;font-size:13px">Chris</div></div>