I&#39;m used to using pymox for most of my mocking but figured I&#39;d give mock a try on some new code.<div><br></div><div>One thing I just ran into:</div><div><br></div><div>mything = Mock(spec=other_function_to_stub_out)</div>

<div>... replace other_function_to_stub_out with mything ...</div><div>mything.return_value = (2, 3)</div><div>def _set_deps(mydict): mydict[&#39;deps&#39;] = [&#39;TEST&#39;]</div><div>mything.side_effect = _set_deps</div>

<div>ThingBeingTested(copy.deepcopy(example_input))</div><div>self.assertEqual(mything.call_count, 1)</div><div>self.assertEqual(mything.call_args, example_input)</div><div><br></div><div>The last assert raises error when example_input does not already contain the modification made my the side_effect.</div>

<div><br></div><div>The mything.side_effect modifies the dictionary argument passed to mything when it was called, that makes sense.  But I was hoping that call_args would be a snapshot of the args at call time (a copy.deepcopy of it) rather than having had the side_effect applied to it.</div>

<div><br></div><div>Is this intentional?</div><div><br></div><div>I can update my side_effect function to include an assert on mydict instead.  But it wasn&#39;t the behavior I expected even though I can see why it probably happens even without digging into the mock sources.</div>

<div><br></div><div>In a pymox world this would&#39;ve been written similar to:</div><div><br></div><div>mything(example_input).AndReturn((2, 3)</div><div>self.mox.ReplayAll()</div><div>ThingBeingTested(copy.deepcopy(example_input))</div>

<div>self.mox.VerifyAll()</div><div><br></div><div>-gps</div>