11import asyncio
2- import gc
32import logging
4- import weakref
53from functools import partial
64from unittest import mock
75
@@ -45,8 +43,6 @@ async def test_done_callback_exception() -> None:
4543
4644
4745async def test_done_callback_exception_logs (caplog : pytest .LogCaptureFixture ) -> None :
48- task : asyncio .Task [None ] | None
49-
5046 caplog .set_level (logging .ERROR , logger = "asyncio" )
5147
5248 wrapped = _LRUCacheWrapper (mock .ANY , None , False , None )
@@ -58,7 +54,6 @@ async def boom() -> None:
5854
5955 key = object ()
6056 task = loop .create_task (boom ())
61- task_ref = weakref .ref (task )
6257 wrapped ._LRUCacheWrapper__cache [key ] = _CacheItem (task , None , 1 ) # type: ignore[attr-defined]
6358 task .add_done_callback (partial (wrapped ._task_done_callback , key ))
6459
@@ -67,16 +62,8 @@ async def boom() -> None:
6762 await asyncio .sleep (0 )
6863
6964 assert key not in wrapped ._LRUCacheWrapper__cache # type: ignore[attr-defined]
70-
71- caplog .clear ()
72-
73- task = None
74- gc .collect ()
75- await asyncio .sleep (0 )
76-
77- assert task_ref () is None
78- assert "Task exception was never retrieved" in caplog .text
79- assert "RuntimeError: boom" in caplog .text
65+ # asyncio disables logging when exception() is called; keep logging enabled.
66+ assert task ._log_traceback # type: ignore[attr-defined]
8067
8168
8269async def test_cache_invalidate_typed () -> None :
0 commit comments