Treat unawaited coroutine warnings as errors in tests

Add pytest filterwarnings to catch unawaited coroutine warnings as
errors. Fix the underlying issue in _await_with_session_monitoring
where a coroutine was not closed before raising when session task
was already done.
This commit is contained in:
Jeremiah Lowin 2026-01-07 13:00:32 -05:00
commit fe31e5252a
2 changed files with 5 additions and 0 deletions

View file

@ -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 = [

View file

@ -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