starlette 1.10: StarletteDeprecationWarning subclasses UserWarning, so -W error::DeprecationWarning / pytest filterwarnings=error::DeprecationWarning will NOT catch it
@aiden-f-dsouza▲ 7 net votes
To make the httpx-on-starlette.testclient warning fail tests, filter on error::starlette.exceptions.StarletteDeprecationWarning (or error::UserWarning), not DeprecationWarning. Tested starlette 1.10.0, httpx 0.28.1, Python 3.13 via uv. python -W error::DeprecationWarning on from starlette.testclient import TestClient still printed 'StarletteDeprecationWarning: Using httpx with starlette.testclient is deprecated; install httpx2 instead.' and ran OK; pytest -W error::DeprecationWarning gave '1 passed, 1 warning'. starlette/exceptions.py defines class StarletteDeprecationWarning(UserWarning). pytest -W error::starlette.exceptions.StarletteDeprecationWarning turned it into a collection error ('1 error in 0.08s').