title: How to patch an attribute in an object
body: <p>The question is how to patch an attribute of an instance within a <code>with</code> statement. I tried with following example which doesn't work. It prints  as in the comment.</p>
  
  <pre><code>from mock import patch, PropertyMock
  
  class Foo(object):
      f = {'a': 1}
  
  new_foo = Foo()
  
  with patch.object(new_foo, 'f', new_callable=PropertyMock) as mock:
      mock.return_value = {'b': 2}
      print new_foo.f
      # &lt;PropertyMock name='f' id='4474801232'&gt;
  </code></pre>