Summary
Every pytest run that touches a TestClient-based test emits:
StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated; install `httpx2` instead.
from starlette.testclient import TestClient as TestClient # noqa
It originates from fastapi/testclient.py importing starlette.testclient, which now prefers the httpx2 client. The environment currently has httpx 0.28.1 installed and no httpx2.
Why it matters
Same rationale as #2740 (the SQLAlchemy MovedIn20Warning): a permanently warning test suite trains everyone to ignore the warnings summary, which is exactly where a real deprecation will eventually hide. Starlette will drop the legacy httpx TestClient path at some point and the suite should be ahead of that.
Proposed fix
- Add
httpx2 to the test/dev requirements so starlette.testclient picks it up (the runtime httpx usage elsewhere in the app is unaffected and can migrate separately if ever needed).
- Verify the suite runs warning-free for this category afterwards:
python -m pytest tests/ -W error::DeprecationWarning -k <testclient-heavy subset> or simply confirm the warnings summary no longer lists it.
Notes
Summary
Every pytest run that touches a TestClient-based test emits:
It originates from
fastapi/testclient.pyimportingstarlette.testclient, which now prefers thehttpx2client. The environment currently hashttpx 0.28.1installed and nohttpx2.Why it matters
Same rationale as #2740 (the SQLAlchemy
MovedIn20Warning): a permanently warning test suite trains everyone to ignore the warnings summary, which is exactly where a real deprecation will eventually hide. Starlette will drop the legacyhttpxTestClient path at some point and the suite should be ahead of that.Proposed fix
httpx2to the test/dev requirements sostarlette.testclientpicks it up (the runtimehttpxusage elsewhere in the app is unaffected and can migrate separately if ever needed).python -m pytest tests/ -W error::DeprecationWarning -k <testclient-heavy subset>or simply confirm the warnings summary no longer lists it.Notes