Skip to content

Commit cab7732

Browse files
committed
fix: suppress uvicorn deprecation warnings in threaded test servers
- Add warnings.filterwarnings in _run_server thread to suppress asyncio.iscoroutinefunction deprecation (Python 3.14+) - Add ResourceWarning filter for unclosed sockets during teardown (Windows) - Add pytest filterwarnings for DeprecationWarning and PytestUnhandledThreadExceptionWarning in pyproject.toml
1 parent f4ea245 commit cab7732

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ filterwarnings = [
186186
"ignore:Returning str or bytes.*:DeprecationWarning:mcp.server.lowlevel",
187187
# pywin32 internal deprecation warning
188188
"ignore:getargs.*The 'u' format is deprecated:DeprecationWarning",
189+
# uvicorn uses asyncio.iscoroutinefunction deprecated in Python 3.14
190+
"ignore:.*asyncio.iscoroutinefunction.*is deprecated:DeprecationWarning",
191+
# Unclosed socket warnings during server teardown (Windows)
192+
"ignore:unclosed.*socket:ResourceWarning",
193+
# Thread exceptions from uvicorn deprecation warnings on Python 3.14
194+
"ignore:Exception in thread.*asyncio.iscoroutinefunction:pytest.PytestUnhandledThreadExceptionWarning",
189195
]
190196

191197
[tool.markdown.lint]

tests/shared/test_streamable_http.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,16 @@ def _start_server_thread(
451451
access_log=False,
452452
)
453453
server = uvicorn.Server(config=config)
454-
thread = threading.Thread(target=server.run, daemon=True)
454+
455+
def _run_server():
456+
import warnings
457+
458+
# Suppress uvicorn deprecation warnings in thread (Python 3.14+)
459+
warnings.filterwarnings("ignore", message=".*asyncio.iscoroutinefunction.*is deprecated")
460+
warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*socket")
461+
server.run()
462+
463+
thread = threading.Thread(target=_run_server, daemon=True)
455464
thread.start()
456465
return thread, server
457466

0 commit comments

Comments
 (0)