Skip to content

Fix test_windows_event_loop_policy for Python 3.14 compatibility#251

Merged
chrishayuk merged 1 commit into
mainfrom
fix/py314-windows-policy-test
Jul 22, 2026
Merged

Fix test_windows_event_loop_policy for Python 3.14 compatibility#251
chrishayuk merged 1 commit into
mainfrom
fix/py314-windows-policy-test

Conversation

@chrishayuk

Copy link
Copy Markdown
Collaborator

Summary

Prerequisite for #221 (Python 3.14 bump). `test_windows_event_loop_policy` fails on 3.14 with a `NameError` from deep inside `asyncio`'s own module `getattr`:

`asyncio.WindowsSelectorEventLoopPolicy` is a lazily-resolved deprecated alias on non-Windows platforms. On Python 3.14, that resolver raises `NameError` instead of `AttributeError` when accessed off Windows (the backing `windows_events` submodule is only imported on win32). `mock.patch(..., create=True)` snapshots the original value via `getattr(target, name, DEFAULT)` before applying the patch, and that call doesn't catch `NameError` — so it blows up before the patch is even applied. This isn't platform-specific to my machine; it reproduces the same way on Linux CI runners.

Fixed by setting/restoring the attribute directly instead of going through `mock.patch`, sidestepping the problematic `getattr` call entirely.

Test plan

asyncio.WindowsSelectorEventLoopPolicy is a lazily-resolved deprecated
alias on non-Windows platforms. On Python 3.14, that resolver raises
NameError instead of AttributeError when accessed off Windows, and
mock.patch(..., create=True) snapshots the original value via
getattr(target, name, DEFAULT) before applying the patch - a call that
doesn't catch NameError, so it blew up before the patch even took
effect.

Set/restore the attribute directly instead, sidestepping that getattr
call. Verified against both Python 3.12 and 3.14.

Signed-off-by: chris hay <chris.hay@uk.ibm.com>
@chrishayuk
chrishayuk merged commit 21fcc8e into main Jul 22, 2026
19 checks passed
@chrishayuk
chrishayuk deleted the fix/py314-windows-policy-test branch July 22, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant