]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-139445: Skip pyrepl tests if the terminal is not supported (GH-154497)... 3.14
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 23 Jul 2026 08:21:52 +0000 (11:21 +0300)
committerGitHub <noreply@github.com>
Thu, 23 Jul 2026 08:21:52 +0000 (08:21 +0000)
They were only skipped if TERM was unset or "dumb", but pyrepl also
needs the terminal to have several capabilities.

(cherry picked from commit 7745710bec7f6de899e97d6f87528035e8977d85)

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Lib/test/test_pyrepl/test_pyrepl.py

index 60561e5663f26c531c239ec41a1e4d1cacb1306f..a10e908e513db9080b770655b0b72c3680e6b0b5 100644 (file)
@@ -11,7 +11,7 @@ import subprocess
 import sys
 import tempfile
 from pkgutil import ModuleInfo
-from unittest import TestCase, skipUnless, skipIf, SkipTest
+from unittest import TestCase, skipUnless, SkipTest
 from unittest.mock import Mock, patch
 from test.support import force_not_colorized, make_clean_env, Py_DEBUG
 from test.support import has_subprocess_support, SHORT_TIMEOUT, STDLIB_DIR
@@ -27,6 +27,7 @@ from .support import (
     multiline_input,
     code_to_events,
 )
+from _pyrepl import terminfo
 from _pyrepl.console import Event
 from _pyrepl._module_completer import (
     ImportParser,
@@ -1530,8 +1531,20 @@ class TestDumbTerminal(ReplTestCase):
         self.assertNotIn("Traceback", output)
 
 
+def supports_pyrepl():
+    # pyrepl falls back to the basic REPL if the terminal lacks any of the
+    # capabilities which UnixConsole requires.  This covers an unset or
+    # "dumb" TERM as well, they are resolved to the "dumb" capabilities.
+    try:
+        info = terminfo.TermInfo(None)
+    except Exception:
+        return False
+    return all(info.get(cap) is not None
+               for cap in ("bel", "clear", "cup", "el"))
+
+
 @skipUnless(pty, "requires pty")
-@skipIf((os.environ.get("TERM") or "dumb") == "dumb", "can't use pyrepl in dumb terminal")
+@skipUnless(supports_pyrepl(), "can't use pyrepl in this terminal")
 class TestMain(ReplTestCase):
     def setUp(self):
         # Cleanup from PYTHON* variables to isolate from local