Last Updated: February 25, 2016
·
1.16K
· claymation

HTTPretty not working with Requests?

You want to test your HTTP client code, so you've written something like:

@httprettified
def test_example():
    HTTPretty.register_uri(HTTPretty.GET,
                           'http://example.com',
                           body='snerble')

    response = requests.get('http://example.com')

    self.assertEquals(response.text, 'snerble')

but it's not working? Requests is adding a trailing slash to your URI, preventing it from matching the URI you've registered.

You need to register the URI like so:

HTTPretty.register_uri(HTTPretty.GET,
                       'http://example.com/',
                       body='snerble')