From c8d3c3f6e7a35c7b06468d4cf56321d77250caba Mon Sep 17 00:00:00 2001 From: AN Long Date: Sun, 10 Sep 2023 20:00:47 +0800 Subject: [PATCH] gh-108996: fix and enable test_msvcrt --- Lib/test/test_msvcrt.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_msvcrt.py b/Lib/test/test_msvcrt.py index 3a63de351e095d..fbbcc71c496c07 100644 --- a/Lib/test/test_msvcrt.py +++ b/Lib/test/test_msvcrt.py @@ -1,9 +1,8 @@ +import ctypes import os import sys import unittest -raise unittest.SkipTest("FIXME! broken test see: https://github.com/python/cpython/pull/109004") - from test.support import os_helper from test.support.os_helper import TESTFN, TESTFN_ASCII @@ -63,6 +62,12 @@ def test_get_osfhandle(self): class TestConsoleIO(unittest.TestCase): + def setUp(self): + # The stdin may have left over contents by other tests (especially test_winconsoleio), + # so flush it before every test case. + h = msvcrt.get_osfhandle(sys.stdin.fileno()) + ctypes.windll.kernel32.FlushConsoleInputBuffer(h) + def test_kbhit(self): self.assertEqual(msvcrt.kbhit(), 0)