Skip to content

Commit ac3b20f

Browse files
committed
test: avoid gc-dependent asyncio log assertion
1 parent 7b0c802 commit ac3b20f

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

tests/test_internals.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import asyncio
2-
import gc
32
import logging
4-
import weakref
53
from functools import partial
64
from unittest import mock
75

@@ -45,8 +43,6 @@ async def test_done_callback_exception() -> None:
4543

4644

4745
async 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

8269
async def test_cache_invalidate_typed() -> None:

0 commit comments

Comments
 (0)