From d15068efc5d3463a108248270b349a3be862e89c Mon Sep 17 00:00:00 2001 From: Umutcan Edizsalan Date: Thu, 23 Jul 2026 15:22:49 +0300 Subject: [PATCH] fix(tests): inject win32gui mock with raising=False so the hwnd tests run on the Linux CI leg Co-authored-by: Cursor --- tests/test_sprint4_com.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/test_sprint4_com.py b/tests/test_sprint4_com.py index fdbc3a1..6c7503f 100644 --- a/tests/test_sprint4_com.py +++ b/tests/test_sprint4_com.py @@ -44,7 +44,9 @@ async def test_find_hwnd_prefers_application_hwnd(monkeypatch): monkeypatch.setattr(cb, "_WIN32_AVAILABLE", True) enum = MagicMock(side_effect=AssertionError("EnumWindows must not be called")) - monkeypatch.setattr(cb, "win32gui", MagicMock(EnumWindows=enum)) + # raising=False: the win32gui module global only exists on Windows; the + # mock must be injectable on the Linux CI leg as well. + monkeypatch.setattr(cb, "win32gui", MagicMock(EnumWindows=enum), raising=False) assert cb._find_autocad_hwnd() == 0xABCD enum.assert_not_called() @@ -56,7 +58,7 @@ async def test_find_hwnd_coerces_hwnd_to_int(monkeypatch): app.HWND = "43981" # COM can hand back a stringy handle monkeypatch.setattr(cb, "_acad_app", lambda: app) monkeypatch.setattr(cb, "_WIN32_AVAILABLE", True) - monkeypatch.setattr(cb, "win32gui", MagicMock()) + monkeypatch.setattr(cb, "win32gui", MagicMock(), raising=False) result = cb._find_autocad_hwnd() assert result == 43981 @@ -81,7 +83,7 @@ async def test_find_hwnd_falls_back_to_enumwindows(monkeypatch): win32gui.EnumWindows.side_effect = _enum_windows win32gui.GetWindowText.return_value = "AutoCAD 2025 - [Drawing1.dwg]" win32gui.IsWindowVisible.return_value = True - monkeypatch.setattr(cb, "win32gui", win32gui) + monkeypatch.setattr(cb, "win32gui", win32gui, raising=False) assert cb._find_autocad_hwnd() == 0x1234 win32gui.EnumWindows.assert_called_once()