From 00573a4cc337a47650245b25ea850f8fb23affc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Wed, 17 Jul 2024 17:36:52 +0200 Subject: [PATCH] gh-120678: Guard against stdin.fileno() being unavailable --- Lib/test/test_pyrepl/test_pyrepl.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py index 6451d6104b5d1a..e6fcb69571c324 100644 --- a/Lib/test/test_pyrepl/test_pyrepl.py +++ b/Lib/test/test_pyrepl/test_pyrepl.py @@ -491,15 +491,23 @@ def prepare_reader(self, events): def test_stdin_is_tty(self): # Used during test log analysis to figure out if a TTY was available. - if os.isatty(sys.stdin.fileno()): - return - self.skipTest("stdin is not a tty") + try: + if os.isatty(sys.stdin.fileno()): + return + except OSError as ose: + self.skipTest(f"stdin tty check failed: {ose}") + else: + self.skipTest("stdin is not a tty") def test_stdout_is_tty(self): # Used during test log analysis to figure out if a TTY was available. - if os.isatty(sys.stdout.fileno()): - return - self.skipTest("stdout is not a tty") + try: + if os.isatty(sys.stdout.fileno()): + return + except OSError as ose: + self.skipTest(f"stdout tty check failed: {ose}") + else: + self.skipTest("stdout is not a tty") def test_basic(self): reader = self.prepare_reader(code_to_events("1+1\n"))