diff --git a/httpretty/core.py b/httpretty/core.py index 9d892033..302aa256 100644 --- a/httpretty/core.py +++ b/httpretty/core.py @@ -1614,8 +1614,7 @@ def historify_request(cls, headers, body='', sock=None): if request not in cls.latest_requests: cls.latest_requests.append(request) else: - pos = cls.latest_requests.index(request) - cls.latest_requests[pos] = request + cls.latest_requests[-1] = request logger.info("captured: {}".format(request)) return request diff --git a/tests/bugfixes/nosetests/test_425_latest_requests.py b/tests/bugfixes/nosetests/test_425_latest_requests.py new file mode 100644 index 00000000..72578c87 --- /dev/null +++ b/tests/bugfixes/nosetests/test_425_latest_requests.py @@ -0,0 +1,29 @@ +import requests +import httpretty +from httpretty.errors import UnmockedError + +from unittest import skip +from sure import expect + + +@httpretty.activate(allow_net_connect=True) +def test_latest_requests(): + "#425 - httpretty.latest_requests() can be called multiple times" + httpretty.register_uri(httpretty.GET, 'http://google.com/', body="Not Google") + httpretty.register_uri(httpretty.GET, 'https://google.com/', body="Not Google") + + requests.get('http://google.com/') + httpretty.latest_requests()[-1].url.should.equal('http://google.com/') + requests.get('https://google.com/') + httpretty.latest_requests()[-1].url.should.equal('https://google.com/') + + httpretty.latest_requests().should.have.length_of(2) + httpretty.latest_requests()[-1].url.should.equal('https://google.com/') + + requests.get('https://google.com/') + httpretty.latest_requests().should.have.length_of(3) + httpretty.latest_requests()[-1].url.should.equal('https://google.com/') + + requests.get('http://google.com/') + httpretty.latest_requests().should.have.length_of(4) + httpretty.latest_requests()[-1].url.should.equal('http://google.com/')