Skip to content

Add httpx2 support - #335

Closed
elviskahoro wants to merge 1 commit into
lundberg:masterfrom
elviskahoro:httpx2-support
Closed

elviskahoro wants to merge 1 commit into
lundberg:masterfrom
elviskahoro:httpx2-support

Conversation

@elviskahoro

Copy link
Copy Markdown

Summary

Adds support for mocking httpx2 (Pydantic's fork of httpx, which depends on httpcore2). Today respx can't mock httpx2: it patches httpx._client.*, and httpx2.Response isn't an instance of httpx.Response.

  • New respx/_compat.py selects the flavour: httpx if installed, otherwise httpx2. RESPX_HTTPX_PACKAGE=httpx2 (or httpx) forces one when both are installed.
  • All modules import httpx/httpcore from the compat module, and mock targets are built from the selected package names (httpx2._client.*, httpcore2._*).
  • Default behaviour is unchanged when httpx is installed. Added an httpx2 extra and a changelog entry.
  • Tests use the compat module and pass on httpx, on httpx2, and with httpx uninstalled, at 100% coverage. Added tests/test_compat.py.

Not included: docs, and an httpx2 job in the CI matrix.

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

Successfully merging this pull request may close these issues.

1 participant