Repository navigation
Closed
Closed
Copy link
Labels
Description
Bug report
Bug description:
test.test_asyncio.test_base_events is calling a real system function with a mocked object, which is causing failures. It seems the test case test_create_connection_happy_eyeballs_ipv4_only is failing.
nick@COMPY D:\src\cpython-trunk>pcbuild\amd64\python.exe -m test
== CPython 3.16.0a0 (heads/main:11f032f904c, Jun 16 2026, 12:13:34) [MSC v.1951 64 bit (AMD64)]
== Windows-11-10.0.26200-SP0 little-endian
== Python build: release with_assert
== cwd: D:\src\cpython-trunk\build\test_python_worker_17156æ
== CPU count: 32
== encodings: locale=cp1252 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests
Using random seed: 1122715071
0:00:00 mem: 30.7 MiB Run 505 tests sequentially in a single process
0:00:00 mem: 30.7 MiB [ 1/505] test.test_asyncio.test_base_events
Exception in callback _ProactorReadPipeTransport._loop_reading()
handle: <Handle _ProactorReadPipeTransport._loop_reading()>
Traceback (most recent call last):
File "D:\src\cpython-trunk\Lib\asyncio\events.py", line 94, in _run
self._context.run(self._callback, *self._args)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\src\cpython-trunk\Lib\asyncio\proactor_events.py", line 306, in _loop_reading
self._read_fut = self._loop._proactor.recv_into(self._sock, self._data)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\src\cpython-trunk\Lib\asyncio\windows_events.py", line 497, in recv_into
self._register_with_iocp(conn)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "D:\src\cpython-trunk\Lib\asyncio\windows_events.py", line 713, in _register_with_iocp
_overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: an integer is required
The TypeError is coming from the return value from obj.fileno() which is returning a <class 'unittest.mock.MagicMock'>.
Tracing the source of that object, it seems it's being created in Lib/test/test_asyncio/utils.py - mock_nonblocking_socket() which doesn't have anything setup to handle fileno() calls. At this point I'm not sure what would be correct to return here as _register_with_iocp() is calling a real system function which would expect a real handle.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Activity
sharktide commentedon Jun 16, 2026
afaik the correct behavior is that the mocked socket must provide a real, integer-valued
fileno(), because the Windows Proactor event loop always calls into an actual OS API (CreateIoCompletionPort) that requires a real Windows handle. AMagicMockobject cannot satisfy that contract, so the test shouldn't allow a mock socket to even get to that code path.test_create_connection_happy_eyeballs_ipv4_onlyusesmock_nonblocking_socket()fromtest_asyncio/utils.py.That helper returns a MagicMock that pretends to be a socket but does not define
fileno().On Windows, the asyncio Proactor loop eventually calls:
But since
obj.fileno()returns aMagicMock, CPython raises:This is technically correct since the OS API must receive a real integer handle... but how should we patch this?
gh-151540: Use a selector event loop in the happy-eyeballs tests (#15…
[3.15] gh-151540: Use a selector event loop in the happy-eyeballs tes…