Skip to content

tests: StarletteDeprecationWarning - TestClient wants httpx2, suite warns on every run #3942

Description

@vdmkenny

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready for reviewDescription complete — ready for maintainer review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions