From 6e81f35309575b498243bfa03a701ece0ab3c092 Mon Sep 17 00:00:00 2001 From: Jakob Rossi Date: Wed, 8 Jul 2026 22:45:41 -0400 Subject: [PATCH] gh-151540: Use a selector event loop in the happy-eyeballs tests test_create_connection_happy_eyeballs and test_create_connection_happy_eyeballs_ipv4_only used asyncio.new_event_loop(), which defaults to ProactorEventLoop on Windows. Creating a socket transport on that loop registers the mocked socket with a real I/O completion port, bypassing the mocked _add_reader/_add_writer and failing in a callback with "TypeError: an integer is required" because MagicMock.fileno() does not return an int. Use asyncio.SelectorEventLoop() explicitly instead, matching the code path these tests already exercise on non-Windows platforms. --- Lib/test/test_asyncio/test_base_events.py | 9 +++++++-- .../Tests/2026-07-08-21-45-00.gh-issue-151540.pQx3Wm.rst | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2026-07-08-21-45-00.gh-issue-151540.pQx3Wm.rst diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py index b4fd7abed5963ea..1622f19f0213f3c 100644 --- a/Lib/test/test_asyncio/test_base_events.py +++ b/Lib/test/test_asyncio/test_base_events.py @@ -1092,7 +1092,11 @@ async def sock_connect(sock, address): await asyncio.sleep(1) sock.connect(address) - loop = asyncio.new_event_loop() + # gh-151540: use a selector event loop instead of the platform + # default; the Windows proactor loop would register the mocked + # socket with a real IOCP handle instead of the mocked + # _add_reader/_add_writer below. + loop = asyncio.SelectorEventLoop() loop._add_writer = mock.Mock() loop._add_writer = mock.Mock() loop._add_reader = mock.Mock() @@ -1124,7 +1128,8 @@ async def sock_connect(sock, address): await asyncio.sleep(1) sock.connect(address) - loop = asyncio.new_event_loop() + # gh-151540: see test_create_connection_happy_eyeballs above. + loop = asyncio.SelectorEventLoop() loop._add_writer = mock.Mock() loop._add_writer = mock.Mock() loop._add_reader = mock.Mock() diff --git a/Misc/NEWS.d/next/Tests/2026-07-08-21-45-00.gh-issue-151540.pQx3Wm.rst b/Misc/NEWS.d/next/Tests/2026-07-08-21-45-00.gh-issue-151540.pQx3Wm.rst new file mode 100644 index 000000000000000..e70ca8f688cddd6 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-07-08-21-45-00.gh-issue-151540.pQx3Wm.rst @@ -0,0 +1,5 @@ +Fix the happy-eyeballs tests in ``test.test_asyncio.test_base_events`` +raising ``TypeError`` in a callback on Windows. The tests now use a +selector event loop explicitly instead of the platform default, as the +Windows proactor event loop registers the mocked test socket with a real +I/O completion port.