Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requesting a URL, then changing the response will return the old response #212

Closed
rbu opened this issue Jul 27, 2018 · 3 comments · Fixed by #455
Closed

Requesting a URL, then changing the response will return the old response #212

rbu opened this issue Jul 27, 2018 · 3 comments · Fixed by #455
Assignees

Comments

@rbu
Copy link
Contributor

rbu commented Jul 27, 2018

The documentation states:

You can also add multiple responses for the same url: ....

However, this is not true if you interleave adding and requesting responses:

>>> import responses
>>> import requests
>>> 
>>> responses.start()
>>> 
>>> responses.add(responses.GET, "https://example.com/",
...     json={'response': 'old'}
... )
>>> requests.get('https://example.com/').content
b'{"response": "old"}'
>>> 
>>> responses.add(responses.GET, "https://example.com/",
...     json={'response': 'new'}
... )
>>> 
>>> 
>>> requests.get('https://example.com/').content
b'{"response": "old"}'
>>> requests.get('https://example.com/').content
b'{"response": "new"}'
>>> requests.get('https://example.com/').content
b'{"response": "new"}'

Expected result: After adding the "new" response, a "new" response is returned in the subsequent request.

Requests version: '2.19.1', Python 3.6.6

@niksite
Copy link

niksite commented Aug 16, 2018

It seems, the feature got broken around 0.6.1 release. It is working on 0.6.0.

@rbu
Copy link
Contributor Author

rbu commented Aug 21, 2018

@niksite This is interesting, I went back to commit 4c90391 (which is part of version 0.5.0) and still saw this behavior. If you have a 0.6.0 environment that does not expose it, could you share the versions of other packages installed (pip freeze) and Python runtime version?

I used this script to test, but without a known good revision it's not possible to bisect:

import sys

try:
    import responses
    import requests

    responses.start()

    responses.add(responses.GET, "https://example.com/",
        json={'response': 'old'}
    )
    assert b'{"response": "old"}' == requests.get('https://example.com/').content

    responses.add(responses.GET, "https://example.com/",
        json={'response': 'new'}
    )

    response = requests.get('https://example.com/')
    if b'{"response": "new"}' == response.content:
        sys.exit(0)
    else:
        print('Got response %r' % response.content)
        sys.exit(1)

except Exception as e:
    print(e)
    sys.exit(125)

@pb-jeff-oneill
Copy link

For me, in some situations the interleaving works fine and in others I get the error described here. This was driving me crazy... I'm surprised the bug exists 2 years later.

@markstory markstory linked a pull request Apr 15, 2021 that will close this issue
beliaev-maksim added a commit to beliaev-maksim/responses that referenced this issue Dec 2, 2021
@beliaev-maksim beliaev-maksim mentioned this issue Dec 2, 2021
holmanb added a commit to holmanb/cloud-init that referenced this issue Apr 6, 2022
holmanb added a commit to holmanb/cloud-init that referenced this issue Apr 6, 2022
@beliaev-maksim beliaev-maksim self-assigned this Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants