title: Python Mock open when there are multiple with open
body: <pre><code>    def second():
          with open(path, 'r') as second_something:
              second_json = json.load(second_something)
      
      def first():
          second()
          with open(path, 'r') as first_something:
              first_json = json.load(first_something)
              
      
      @patch('builtins.open', new_callable=mock_open, read_data='{&quot;hello&quot;:&quot;yes&quot;}')
      @patch('builtins.open', new_callable=mock_open, read_data='{&quot;world&quot;:&quot;no&quot;}')
      def test_first(self):
          first()
          #doing asserting here
          assert(fist_json,{&quot;world&quot;:&quot;no&quot;})
  </code></pre>
  <p>Writing a test case for &quot;<strong>first</strong>&quot; function and want to mock both &quot;with open&quot; statment, so wrote two @patch but both are getting <strong>'{&quot;hello&quot;:&quot;yes&quot;}</strong>', instead of one getting '<strong>{&quot;hello&quot;:&quot;yes&quot;}</strong>' and another <strong>'{&quot;world&quot;:&quot;no&quot;}'</strong>. Having trouble with mocking this, please help me out.</p>