Skip to content

Commit 2c3211a

Browse files
gh-139445: Skip pyrepl tests if the terminal is not supported (GH-154497)
They were only skipped if TERM was unset or "dumb", but pyrepl also needs the terminal to have several capabilities. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> (cherry picked from commit 7745710)
1 parent 4190495 commit 2c3211a

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import sys
1212
import tempfile
1313
from pkgutil import ModuleInfo
14-
from unittest import TestCase, skipUnless, skipIf, SkipTest
14+
from unittest import TestCase, skipUnless, SkipTest
1515
from unittest.mock import Mock, patch
1616
from test.support import force_not_colorized, make_clean_env, Py_DEBUG
1717
from test.support import has_subprocess_support, SHORT_TIMEOUT, STDLIB_DIR
@@ -27,6 +27,7 @@
2727
multiline_input,
2828
code_to_events,
2929
)
30+
from _pyrepl import terminfo
3031
from _pyrepl.console import Event
3132
from _pyrepl._module_completer import (
3233
ImportParser,
@@ -1530,8 +1531,20 @@ def test_dumb_terminal_exits_cleanly(self):
15301531
self.assertNotIn("Traceback", output)
15311532

15321533

1534+
def supports_pyrepl():
1535+
# pyrepl falls back to the basic REPL if the terminal lacks any of the
1536+
# capabilities which UnixConsole requires. This covers an unset or
1537+
# "dumb" TERM as well, they are resolved to the "dumb" capabilities.
1538+
try:
1539+
info = terminfo.TermInfo(None)
1540+
except Exception:
1541+
return False
1542+
return all(info.get(cap) is not None
1543+
for cap in ("bel", "clear", "cup", "el"))
1544+
1545+
15331546
@skipUnless(pty, "requires pty")
1534-
@skipIf((os.environ.get("TERM") or "dumb") == "dumb", "can't use pyrepl in dumb terminal")
1547+
@skipUnless(supports_pyrepl(), "can't use pyrepl in this terminal")
15351548
class TestMain(ReplTestCase):
15361549
def setUp(self):
15371550
# Cleanup from PYTHON* variables to isolate from local

0 commit comments

Comments
 (0)