Unit Testing a Function That Calls a url with Mock
<h1>Question</h1>

<p>I have a function that calls a url and then modifies that url's response. How can I write a unit test for the portion of that function's code that modifies the response, without having to rely on that url?</p>

<h2>Example</h2>

<h3>my_module.py</h3>

<pre><code>import requests

def get_some_resource():
    url = 'http://httpbin.org/get'
    r = requests.get(url)
    # Special manipulation of returned text (what I want to test) simple example used
    output = r.text.upper()
    return output
</code></pre>

<h2>What I've tried so far</h2>

<ul>
<li>Using mock's MagicMock() (you can't use it to override a function's variables, as far as I can tell)</li>
<li>I've considered breaking apart the two sections of that function (the retrieval of the url and the modify of the response), however, I'm not clear if that's necessary</li>
<li>So much googling my hands hurt</li>
</ul>
