title: How do I mock class instance attributes?
body: <pre class="lang-py prettyprint-override"><code>class MyClass:
      def __init__(self, a, b):
          self.a = a
          self.b = b
   
  def myFunc():
      myClass = MyClass(1, 2)
      print(myClass.a, myClass.b)
  </code></pre>
  <p>In my test, I want to run <code>myFunc()</code> but inside <code>myFunc()</code> I want <code>myClass</code> to return <code>'test1'</code> and <code>'test2'</code> as its <code>a</code> and <code>b</code> attributes.</p>
  <p>So I did this:</p>
  <pre class="lang-py prettyprint-override"><code>with patch('__main__.MyClass') as MockClass:
      instance = MockClass.return_value
      instance.a.return_value = 'test1'
      instance.b.return_value = 'test2'
      myFunc()
  </code></pre>
  <p>However, the result is <code>&lt;MagicMock name=MyClass().a' id='2938383'&gt;</code>..... Instead of simply <code>'test1'</code> and <code>'test2'</code>.</p>
  <p>What am I doing wrong? What am I misunderstanding about how to use mock?</p>