Skip to content

Commit 25a820f

Browse files
committed
Fix test_task_factory for Python 3.11 compatibility
The eager_start parameter for asyncio.Task was introduced in Python 3.12. Use version check to fall back to loop parameter on Python 3.10-3.11.
1 parent 854444c commit 25a820f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

priv/tests/test_base.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import contextvars
2828
import gc
2929
import socket
30+
import sys
3031
import threading
3132
import time
3233
import unittest
@@ -475,8 +476,13 @@ def test_task_factory(self):
475476

476477
def task_factory(loop, coro):
477478
factory_calls.append(True)
478-
# Create task using modern API (Python 3.12+)
479-
return asyncio.Task(coro, eager_start=False)
479+
# Create task compatible with all Python versions
480+
if sys.version_info >= (3, 12):
481+
# Python 3.12+: use eager_start=False to opt out of eager execution
482+
return asyncio.Task(coro, eager_start=False)
483+
else:
484+
# Python 3.10-3.11: loop parameter deprecated but still works
485+
return asyncio.Task(coro, loop=loop)
480486

481487
self.loop.set_task_factory(task_factory)
482488
self.assertEqual(self.loop.get_task_factory(), task_factory)

0 commit comments

Comments
 (0)