Skip to content

Commit ff4239d

Browse files
committed
fix: suppress DeprecationWarning in threaded uvicorn server
Python 3.14 deprecates asyncio.iscoroutinefunction(), which uvicorn calls internally. With pytest's filterwarnings=['error'], this DeprecationWarning becomes an exception that kills the server thread before it can start listening. In multiprocessing mode this was hidden because child processes don't inherit pytest's warning filters. Threading shares the same process, so we need to explicitly suppress DeprecationWarnings in the server thread.
1 parent 375e862 commit ff4239d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/shared/test_streamable_http.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import threading
1212
import time
1313
import traceback
14+
import warnings
1415
from collections.abc import AsyncIterator, Generator
1516
from contextlib import asynccontextmanager
1617
from dataclasses import dataclass, field
@@ -1553,7 +1554,13 @@ def _create_context_aware_server(port: int) -> uvicorn.Server:
15531554
def context_aware_server(basic_server_port: int) -> Generator[None, None, None]:
15541555
"""Start the context-aware server on a background thread (in-process for coverage)."""
15551556
server_instance = _create_context_aware_server(basic_server_port)
1556-
thread = threading.Thread(target=server_instance.run, daemon=True)
1557+
1558+
def _run() -> None:
1559+
with warnings.catch_warnings():
1560+
warnings.filterwarnings("ignore", category=DeprecationWarning)
1561+
server_instance.run()
1562+
1563+
thread = threading.Thread(target=_run, daemon=True)
15571564
thread.start()
15581565

15591566
wait_for_server(basic_server_port)

0 commit comments

Comments
 (0)