title: Testing that class instance supplied to mock function has correct attributes
body: <p>I have a class <code>MyClass</code> and two functions <code>my_function</code> and <code>my_other_function</code>. <code>my_other_function</code> calls <code>my_function</code>. I would like to test <code>my_other_function</code> and mock out <code>my_function</code>. The problem is, <code>my_function</code> takes an instance of <code>MyClass</code> as its argument and accesses the <code>foo</code> attribute of it. <code>my_other_function</code> alters the <code>foo</code> attribute. I want to test that the calls made to the mock <code>my_function</code> use the correct arguments, which involves ensuring that that the <code>foo</code> attribute of the <code>MyClass</code> instance is correct each time. I'm not sure how to do this because by the time I access the <code>call_args_list</code> attribute of the mock the class has already been modified and I can only see its most recent state</p>
  
  <pre><code>import mock
  class MyClass(object):
      def __init__(self):
          self.foo = 'a'
  
  def my_function(instance):
      print instance.foo
  
  
  def my_other_function():
      myinstance = MyClass()
      for i in ['a','b','c']:
          myinstance.foo = i 
          my_function(myinstance)
  
  
  def test_my_other_function():
      with mock.patch(__name__+'.my_function') as mock_function:
          my_other_function()
          mock_function.call_args_list
          # Test that the instance passed to my_function had the correct foo attribute each time
  </code></pre>
  
  <p>Each call in the <code>calls_args_list</code> just shows the most recent state of <code>myinstance</code>, with <code>foo</code> being 'c'</p>