How do I mock a method that uses requests.get in my class?
<p>I'm attempting to create a few unit tests for my class. I want to mock these, so that I don't burn through my API quota running some of these tests. I have multiple test cases that will call the <code>fetch</code> method, and depending on the passed URL I'll get different results back.</p>

<p>My <em>example</em> class looks like this:</p>

<pre><code>import requests
class ExampleAPI(object):
    def fetch(self, url, params=None, key=None, token=None, **kwargs):
        return requests.get(url).json() # Returns a JSON string
</code></pre>

<p>The <a href="http://seminar.io/2013/09/27/testing-your-rest-client-in-python/" rel="nofollow">tutorial</a> I'm looking at shows that I can do something like this:</p>

<pre><code>import unittest
from mock import patch

def fake_fetch_test_one(url):
    ...

class TestExampleAPI(unittest.TestCase):
    @patch('mymodule.ExampleAPI.fetch', fake_fetch_test_one)
    def test_fetch(self):
        e = ExampleAPI()
        self.assertEqual(e.fetch('http://my.api.url.example.com'), """{'result': 'True'}""")
</code></pre>

<p>When I do this, though, I get an error that says:</p>

<pre><code>TypeError: fake_fetch_test_one() takes exactly 1 argument (3 given)
</code></pre>

<p>What is the proper way to mock a <code>requests.get</code> call that is in a method in my class? I'll need the ability to change the mock'd response per test, because different URLs can provide different response types.</p>