From 8932045476f371fab5814daa056183e19345ba1b Mon Sep 17 00:00:00 2001 From: basil-k-aji-dev <70605804+basil-k-aji-dev@users.noreply.github.com> Date: Mon, 14 Sep 2026 14:30:05 +0530 Subject: [PATCH] test(mcp): let the emulator win32 branch be exercised from any host `test_ensure_emulator_uses_windows_creation_flags` patches `sys.platform` to "win32" so the Windows spawn path can be tested anywhere, but that path builds `subprocess.CREATE_NEW_PROCESS_GROUP | subprocess.DETACHED_PROCESS` and neither attribute exists off Windows. The expression raises AttributeError before Popen is reached, `ensure_emulator`'s `except Exception: return False` swallows it, and the test fails its first assertion as a bare `assert False` on Linux and macOS -- including CI's own ubuntu-latest runner. Stub the two constants with their documented Windows values. The assertion compares against the same attributes, so it keeps its meaning: injecting a regression that swaps the win32 branch to `start_new_session` still fails the test with KeyError: 'creationflags'. Test-only. The broad `except Exception` that hid this is raised in the issue for a maintainer decision rather than changed here. Closes #97. --- tests/unit/mcp/test_device_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/unit/mcp/test_device_utils.py b/tests/unit/mcp/test_device_utils.py index 02fa97f3..7f65cea8 100644 --- a/tests/unit/mcp/test_device_utils.py +++ b/tests/unit/mcp/test_device_utils.py @@ -9,6 +9,15 @@ def test_ensure_emulator_uses_windows_creation_flags(monkeypatch) -> None: popen = MagicMock() monkeypatch.setattr(device_utils.sys, "platform", "win32") + # CREATE_NEW_PROCESS_GROUP and DETACHED_PROCESS exist in subprocess only on + # Windows, so reaching the win32 branch from a POSIX host needs them stubbed + # with their documented values. Without them the branch raises + # AttributeError, ensure_emulator's `except Exception: return False` + # swallows it, and this test can only pass on a Windows runner. + monkeypatch.setattr( + device_utils.subprocess, "CREATE_NEW_PROCESS_GROUP", 0x00000200, raising=False + ) + monkeypatch.setattr(device_utils.subprocess, "DETACHED_PROCESS", 0x00000008, raising=False) monkeypatch.setattr(device_utils, "is_emulator_running", lambda _adb: False) monkeypatch.setattr(device_utils.os.path, "exists", lambda _path: True) monkeypatch.setattr(device_utils.subprocess, "Popen", popen)