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

Response reason should be set based on status_code #261

Open
soxofaan opened this issue Jul 8, 2024 · 1 comment
Open

Response reason should be set based on status_code #261

soxofaan opened this issue Jul 8, 2024 · 1 comment

Comments

@soxofaan
Copy link
Contributor

soxofaan commented Jul 8, 2024

(Instead of piggybacking on the old #118, It thought it was better to start a new ticket)

PR #126 tried to address #118, but I think that fix never worked, I still get this with latest requests-mock 1.12.1:

url = "https://example.com/notfound"
with requests_mock.Mocker() as m:
    m.get(url, status_code=404)
    requests.get(url).raise_for_status()

HTTPError: 404 Client Error: None for url: https://example.com/notfound

Note the "None" instead of "Not Found"

@soxofaan
Copy link
Contributor Author

soxofaan commented Jul 8, 2024

#126 basically added this:

reason = kwargs.get('reason', http.client.responses.get(status))

But in reality that fallback value is never used because the "reason" is actually set (e.g. to None unless user specified something else), as create_response is called roughly like this:

context = _Context(...
    self._params.get('reason'),
)
...
return create_response(...
    reason=context.reason,

I guess a better fix is to also add a fallback value to that self._params.get('reason') call

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

No branches or pull requests

1 participant