gabrielfalcao / HTTPretty

Intercept HTTP requests at the Python socket level. Fakes the whole socket module

Home Page:https://httpretty.readthedocs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect examples in documentation (contextmanager)

romuald opened this issue · comments

The examples for various context managers seems to be outdated.

For example: https://httpretty.readthedocs.io/en/1.1.4/api.html#httpretty.core.httprettized

In documentation:

httpretty.register_uri(httpretty.GET, 'https://httpbin.org/ip', body=json.dumps({'origin': '42.42.42.42'}))
with httpretty.enabled():
    response = requests.get('https://httpbin.org/ip')

Actual code needs the register_uri call to be made inside the with statement, otherwise it is not mocked

python version 3.7
httpretty version 1.1.4

Thanks for the report @romuald

Another symptom of this issue is that the requests end up taking quite long. E.g. 75 seconds for a simple request.head(URL).