From da965db5cb460aef9f0341556a2bd4ad5f61846c Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Wed, 7 Jan 2026 14:29:56 -0500 Subject: [PATCH] Fix unawaited coroutine warning and treat as test error (#2806) --- pyproject.toml | 3 +++ src/fastmcp/client/client.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 6b41c1ae3..22fdd6b68 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,6 +110,9 @@ filterwarnings = [ # Suppress OAuth in-memory token storage warnings in tests # Tests intentionally use ephemeral storage; this warning is for end users "ignore:Using in-memory token storage:UserWarning", + # Treat unawaited coroutine warnings as errors - these are almost always bugs + "error:coroutine .* was never awaited:RuntimeWarning", + "error:Exception ignored in.*coroutine:pytest.PytestUnraisableExceptionWarning", ] timeout = 5 env = [ diff --git a/src/fastmcp/client/client.py b/src/fastmcp/client/client.py index 4b8488280..910b6d998 100644 --- a/src/fastmcp/client/client.py +++ b/src/fastmcp/client/client.py @@ -686,6 +686,8 @@ class Client(Generic[ClientTransportT]): # If session task already failed, raise immediately if session_task.done(): + # Close the coroutine to avoid "was never awaited" warning + coro.close() exc = session_task.exception() if exc: raise exc