Skip to content

Commit af83029

Browse files
committed
fix: improve resource cleanup in test_load_remote_resources and update mock handling in test_close_remote_resources
1 parent 011a2a2 commit af83029

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

sources/test_manager_download.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import asyncio
22
import logging
33
import os
4-
from unittest.mock import AsyncMock, patch
4+
from unittest.mock import AsyncMock, MagicMock, patch
55

66
import pytest
77
import pytest_asyncio
@@ -188,6 +188,9 @@ async def test_load_remote_resources(mock_client):
188188

189189
finally:
190190
# Clean up
191+
for resource in DownloadManager._REMOTE_RESOURCES_CACHE.values():
192+
if asyncio.iscoroutine(resource):
193+
await resource
191194
DownloadManager._REMOTE_RESOURCES_CACHE.clear()
192195

193196

@@ -314,14 +317,14 @@ async def test_close_remote_resources():
314317
# Arrange
315318
mock_task = AsyncMock(spec=asyncio.Task)
316319
mock_awaitable = AsyncMock()
317-
mock_awaitable.__await__ = AsyncMock(
318-
return_value=iter([None])
319-
) # Make it properly awaitable
320+
mock_awaitable.__await__ = AsyncMock(return_value=iter([None]))
320321

321322
# Configure mock task
322323
mock_task.done.return_value = False
323324
mock_task.cancelled.return_value = False
324-
mock_task.cancel = AsyncMock()
325+
mock_task.cancel = (
326+
MagicMock()
327+
) # Use regular MagicMock instead of AsyncMock for cancel
325328

326329
# Store original cache
327330
original_cache = DownloadManager._REMOTE_RESOURCES_CACHE.copy()
@@ -338,7 +341,6 @@ async def test_close_remote_resources():
338341

339342
# Assert
340343
mock_task.cancel.assert_called_once()
341-
# No need to await mock_awaitable as it's handled in close_remote_resources
342344

343345
finally:
344346
# Restore original cache

0 commit comments

Comments
 (0)