title: Mocking urllib2.urlopen().read() for different responses
body: <p>I am trying to mock the urllib2.urlopen library in a way that I should get different responses for different urls I pass into the function.</p>
  
  <p>The way I am doing it in my test file now is  like this</p>
  
  <pre><code>@patch(othermodule.urllib2.urlopen)
  def mytest(self, mock_of_urllib2_urllopen):
      a = Mock()
      a.read.side_effect = ["response1", "response2"]
      mock_of_urllib2_urlopen.return_value = a
      othermodule.function_to_be_tested()   #this is the function which uses urllib2.urlopen.read
  </code></pre>
  
  <p>I expect the the othermodule.function_to_be_tested to get the value "response1" on first call and "response2" on second call which is what side_effect will do</p>
  
  <p>but the othermodule.function_to_be_tested() receives </p>
  
  <pre><code>&lt;MagicMock name='urlopen().read()' id='216621051472'&gt;
  </code></pre>
  
  <p>and not the actual response. Please suggest where I am going wrong or an easier way to do this.</p>