Repository navigation
Conversation
All respx imports of httpx now go through respx.httpxlib, which uses httpx when installed, else httpx2, or the one set by the RESPX_HTTPX env var. The httpx mocker targets the picked client, and the httpcore mocker responds with the httpcore flavour of the intercepted request.
2 tasks done
1 of 2 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on #317 and follows the direction from #316: one respx package that works with either
httpxorhttpx2.respx/httpxlib.py, like httpx's jsonlib. Every respx module importshttpxandhttpcorefrom there. It pickshttpxif installed, otherwisehttpx2.RESPX_HTTPX=httpxorRESPX_HTTPX=httpx2picks explicitly, e.g. when both are installed. It has to be set before pytest starts, since the plugin imports respx early.httpxmocker patches the picked client. The defaulthttpcoremocker keeps patching both httpcore and httpcore2, as in Supporthttpx2via httpcore2 #317, so requests can't slip through to the network when both are installed.RESPX_HTTPX2as always true (mypyalways_true, pyrightdefineConstant) type-checks against httpx2 instead.respx[httpx]andrespx[httpx2]extras. httpx stays a regular dependency for now, so nothing changes for current installs.toolparameter in the noxfile and the CI matrix. Coverage stays at 100% in each, and mypy runs for both.I also ran openai-python's test suite with its vendored
tests/respx2pointed at this branch through a small adapter, and no test changed outcome.Open question: with httpx still required,
pip install respx[httpx2]also installs httpx, so httpx2 users needRESPX_HTTPX=httpx2until httpx becomes optional. Dropping it frominstall_requiresis a one-line change and the httpx2-only env already covers that layout. Happy to do it here or in a follow-up, whichever you prefer.CI grows from 7 to 17 test jobs. If that's too many I can trim the matrix to fewer Python versions for the httpx2 and both-installed envs.