title: How to use mock_open() with patch.object() in test annotation
body: <p>I'm trying to mock read from file. Using examples it can be done with a construction like:</p>
  
  <pre><code>with patch('__builtin__.open', mock_open(read_data='1'), create=True) as m:
      with open('foo') as h:
          result = h.read()
  </code></pre>
  
  <p>I wonder, is there a way to mock open function using my testcase annotation. Like:</p>
  
  <pre><code>@patch.object(__builtin__, 'open')
  def test_check_status_running(self, m_open):
  </code></pre>
  
  <p>I don't find the correct way, because for me it works for int and doesn't work for strings:</p>
  
  <pre><code>@patch.object(__builtin__, 'open')
  def test_check_status_running1(self, m_open):
      m_open = mock_open(read_data='1')
      pid = open('testfile').read().strip()
      print type(pid)                    # &lt;class 'mock.MagicMock'&gt;
      self.assertEqual(1, int(pid))      # Pass
      self.assertEqual('1', pid)         # Fails MismatchError: '1' != &lt;MagicMock name='open().read()' id='39774928'&gt;
  </code></pre>