getsentry / responses

A utility for mocking out the Python Requests library.
Apache License 2.0
4.08k stars 347 forks source link

Add support for drop-in replacement Niquests when installed #725

Open Ousret opened 1 week ago

Ousret commented 1 week ago

Close #710 Close https://github.com/jawah/niquests/issues/109

responses remain attached to Requests indefinitely, but there is an opportunity to support another http client fully compatible with Requests, namely Niquests.

The commit add a thin layer of compat logic to import Niquests instead of Requests if present in the environment. At the time of this commit, Niquests is not likely to be present in one's environment unless that is what the user wanted.

An escape hatch is also present, in case both Niquests and Requests are present and the user wants to mock Requests only. Setting "RESPONSES_USE_REQUESTS" with any value inside revert to using Requests only.

Unfortunately, for the time being, no simple ways emerge to support both library at once.

Comments will be attached to justify every changes. I tried to make it as light as possible. Of course, if anything started to make your life harder, I will surely come and help as much as I can.

This would offer Niquests users, a reliable way to mock http responses. Lastly, Niquests does have async via AsyncSession, that is a mirror of its synchronous counterpart, and for now, I have no idea how it would be conceivable to support it here. It's not the topic of this PR. Just to brought it up.

regards,