title: Mock patch a function that doesn't exist on a class
body: <p>Using Python's <a href="http://www.voidspace.org.uk/python/mock/index.html" rel="noreferrer">mock</a> framework, is it possible to mock patch a function that doesn't exist on a class. If so, how?</p>
  
  <p>For example:</p>
  
  <p><em>example.py</em>  </p>
  
  <pre><code>import mock
  import unittest
  
  
  class MyClass(object):
      pass
  
  
  class MyTests(unittest.TestCase):
  
      def test_mock_non_existent_function(self):
          with mock.patch('example.MyClass.my_function'):
              pass
  </code></pre>
  
  <p>Running that test raises an error:</p>
  
  <pre><code>Error
  Traceback (most recent call last):
    File "/Users/jesse/Code/my_proj/lib/mock.py", line 1193, in patched
    File "/Users/jesse/Code/my_proj/lib/mock.py", line 1268, in __enter__
    File "/Users/jesse/Code/my_proj/lib/mock.py", line 1242, in get_original
  AttributeError: &lt;class 'example.MyClass'&gt; does not have the attribute 'my_function'
  </code></pre>
  
  <p>Using <code>Python 2.7.9</code> and <code>mock 1.0.1</code>.</p>