Support httpx2 in the test client

Merged
KL
5mo ago
+32-7

starlette.testclient now prefers httpx2 when installed, falling back to httpx. The fallback emits a StarletteDeprecationWarning urging migration; if neither is installed, the existing RuntimeError is raised pointing at httpx2.

Non-breaking: users with only httpx installed keep working, just warned.

  • Adds StarletteDeprecationWarning(UserWarning) to starlette/exceptions.py (from #3119) - inherits from UserWarning so it's visible by default.
  • TYPE_CHECKING guard keeps mypy typing against httpx (httpx2 has no stubs yet).

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.