title: Python Mock - Mocking several open
body: <p>After reading this : <a href="https://stackoverflow.com/q/1289894/259576">How do I mock an open used in a with statement (using the Mock framework in Python)?</a></p>
  
  <p>I'm able to mock the open function in python using :</p>
  
  <pre><code>with patch(open_name, create=True) as mock_open:
      mock_open.return_value = MagicMock(spec=file)
      m_file = mock_open.return_value.__enter__.return_value
      m_file.read.return_value = 'text1'
  
      diffman = Diffman()
      diffman.diff(path1, path2)
  </code></pre>
  
  <p>It works well when my tested method used one open statement. Here is my tested method :</p>
  
  <pre><code>def diff(self, a, b):
      with open(a, 'r') as old:
          with open(b, 'r') as new:
              oldtext = old.read()
              newtext = new.read()
  </code></pre>
  
  <p>The values of oldtext and newtext are the same ('text1' here).</p>
  
  <p>I would like to have 'text1' for the oldtext and 'text2' for the newtext.</p>
  
  <p>How can I do this ?</p>