diff --git a/tests/windows/conftest.py b/tests/windows/conftest.py index 39817fc..91f0556 100644 --- a/tests/windows/conftest.py +++ b/tests/windows/conftest.py @@ -3,8 +3,8 @@ import pytest -if sys.platform in ("win32", "cygwin"): - import msvcrt +# if sys.platform in ("win32", "cygwin"): +# import msvcrt # ignore all tests in this folder if not on windows @@ -14,10 +14,16 @@ def pytest_ignore_collect(path, config): @pytest.fixture -def patched_stdin(): +def patched_stdin(monkeypatch): class mocked_stdin: def push(self, string): - for c in string: - msvcrt.ungetch(ord(c).to_bytes(1, "big")) + # Create an iterator from the string + characters = iter(string) + + # Patch msvcrt.getwch to return the next character from the iterator. + # Don't use next(iter(string)) as it creates a new iterator each time. + # For example, + # if you use a new iterator, cursor_up (\x00\x48) will be read as \x00\x00. + monkeypatch.setattr("msvcrt.getwch", lambda: next(characters)) return mocked_stdin()