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

Record/Replay feature returns incorrect HTTP status code #441

Open
mhaas opened this issue Sep 17, 2021 · 1 comment · May be fixed by #476
Open

Record/Replay feature returns incorrect HTTP status code #441

mhaas opened this issue Sep 17, 2021 · 1 comment · May be fixed by #476
Assignees

Comments

@mhaas
Copy link

mhaas commented Sep 17, 2021

I am not sure if this feature is already released since #10 is still open. However, "record and playback" is present in the main README, so I gave it a shot.

It seems that HTTP status codes are not replayed correctly:

def test_record_replay_2():
    record_file = "/tmp/http_2.json"

    if os.path.exists(record_file):
        context_manager = httpretty.HTTPretty.playback(record_file, allow_net_connect=False,
                                      verbose=True)
    else:
        context_manager = httpretty.HTTPretty.record(record_file, allow_net_connect=True, verbose=True)

    with context_manager:
        response = requests.get("https://httpstat.us/500")
    assert response.status_code == 500

On the second time the test is run, the "playback" feature will be used, but the assertion will fail:

        with context_manager:
            response = requests.get("https://httpstat.us/500")
>       assert response.status_code == 500
E       assert 200 == 500

More interestingly, this issue does not happen when the test is executed as follows:

def test_record_replay():
    record_file = "/tmp/http.json"

    def request_and_test():
        response = requests.get("https://httpstat.us/500")
        assert response.status_code == 500

    with httpretty.HTTPretty.record(record_file, allow_net_connect=True, verbose=True):
        request_and_test()

    with httpretty.HTTPretty.playback(record_file, allow_net_connect=False,
                                      verbose=True):
        request_and_test()

Is this an operator error here or is there a real bug here? I do not see the issue with my code, but that does not mean it is not there.

@mhaas mhaas changed the title Record/Replay feature does not consider HTTP status codes Record/Replay feature returns incorrect HTTP status code Sep 17, 2021
@gabrielfalcao gabrielfalcao self-assigned this Oct 12, 2021
@gabrielfalcao
Copy link
Owner

@mhaas thanks for reporting, I'll work on a fix as soon as possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants