HTTPretty icon indicating copy to clipboard operation
HTTPretty copied to clipboard

HTTPretty freezes when a request to an umocked url is made with requests

Open k-nut opened this issue 8 years ago • 2 comments

Given httpretty 0.8.14 and the following code:

import requests
import httpretty
import urllib2


@httpretty.activate
def test_passing():
    httpretty.HTTPretty.allow_net_connect = True
    httpretty.register_uri(httpretty.GET, "http://yipit.com/",
                           body="Find the best daily deals")

    response = requests.get('http://yipit.com')
    fd = urllib2.urlopen('http://google.com')
    response2 = fd.read()
    fd.close()
    print "Urllib request done"

    assert response.text == "Find the best daily deals"


@httpretty.activate
def test_failing():
    httpretty.HTTPretty.allow_net_connect = True
    httpretty.register_uri(httpretty.GET, "http://yipit.com/",
                           body="Find the best daily deals")

    response = requests.get('http://yipit.com')
    response2 = requests.get('http://google.com')
    print "Requests request done"

    assert response.text == "Find the best daily deals"


if __name__ == "__main__":
    test_passing()
    test_failing()

The first test (test_passing) runs without problems. The second test which only differs by making the second request to google with requests instead of urllib2 never prints anything and just freezes.

Is there anything I am missing here?

k-nut avatar Jun 01 '16 08:06 k-nut

On closer inspection this seems to be a duplicate of https://github.com/gabrielfalcao/HTTPretty/issues/65

k-nut avatar Jun 01 '16 10:06 k-nut

Same problem

python: 3.8.2 httpretty: 1.0.2 requests: 2.22.0

Following script never ends

import httpretty
import requests

httpretty.enable()
requests.get('http://example.com')
httpretty.disable()

belkka avatar Apr 16 '20 11:04 belkka