From f16a63ebf918f78c6901b223585a6707cd473fbb Mon Sep 17 00:00:00 2001 From: jeishod Date: Thu, 27 Aug 2026 15:28:56 +0100 Subject: [PATCH] test(alerting): close the coroutine the create_task mock intercepts update_values builds periodic_flush() before handing it to the patched asyncio.create_task, which neither schedules nor closes it, so garbage collection emits an unawaited-coroutine warning. That is noise normally and an error under -W error. Applies to the pre-existing start test as well: it patches create_task the same way, so fixing only the new one would leave the warning in place. --- .../SlackAlerting/test_slack_alerting.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test_litellm/integrations/SlackAlerting/test_slack_alerting.py b/tests/test_litellm/integrations/SlackAlerting/test_slack_alerting.py index 167b6c110fb..c21f274eafc 100644 --- a/tests/test_litellm/integrations/SlackAlerting/test_slack_alerting.py +++ b/tests/test_litellm/integrations/SlackAlerting/test_slack_alerting.py @@ -15,6 +15,16 @@ from litellm.proxy._types import CallInfo, Litellm_EntityType from litellm.types.integrations.slack_alerting import SlackAlertingCacheKeys +def _close_and_stub(coro): + """asyncio.create_task stand-in: close the coroutine nothing will await. + + Leaving it open emits an unawaited-coroutine warning, which is an error + under -W error. + """ + coro.close() + return MagicMock() + + class TestSlackAlerting(unittest.TestCase): def setUp(self): self.slack_alerting = SlackAlerting() @@ -156,8 +166,7 @@ class TestSlackAlerting(unittest.TestCase): # Calling update_values with alerting args should try to start the periodic task @patch("asyncio.create_task") def test_update_values_starts_periodic_task(self, mock_create_task): - # Make it do nothing (or return a dummy future) - mock_create_task.return_value = AsyncMock() # prevents awaiting errors + mock_create_task.side_effect = _close_and_stub assert self.slack_alerting.periodic_started == False @@ -169,7 +178,7 @@ class TestSlackAlerting(unittest.TestCase): # never exits, so they accumulate for the lifetime of the process). @patch("asyncio.create_task") def test_update_values_starts_periodic_task_only_once(self, mock_create_task): - mock_create_task.return_value = AsyncMock() + mock_create_task.side_effect = _close_and_stub for _ in range(5): self.slack_alerting.update_values(alerting=["slack"])