title: Is it possible to patch a class instance with an existing Singleton instance?
body: <p><br>
  I have a class representing our DB layer which is being instantiated internally in some classes (I cannot pass it as an outside parameter)<br>
  For example:<br></p>
  
  <pre><code>class MyClass(object):
      def __init__(self):
          self.dbapi = DatabaseAPI()
          self.timeout = 120
  
      def some_methods(self):
          pass
  </code></pre>
  
  <p>We're writing some Unit tests, and we'd like to mock the self.dbapi with an existing instance which we'll be creating before the test runs.</p>
  
  <p>for example:</p>
  
  <pre><code>my_dbapi = DatabaseAPIMock()
  ...
  ...
  @patch('MyModule.DatabaseAPI', my_dbapi)
  def my_test(self):
      my_class = MyClass() #&lt;---This is where I'm not able to mock the DatabaseAPI
  </code></pre>
  
  <p>This is what I tried to achieve so far, but from debugging the code I see that the self.dbapi is instantiated with the real object and not with the pre-made mock.</p>
  
  <p>What am I missing?<br>
  BTW, we're running python 2.7<br></p>
  
  <p>Thanks in advance!</p>