Skip to content

Commit bbfca06

Browse files
gh-139445: Skip pyrepl tests if the terminal is not supported
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>
1 parent 13e3f8a commit bbfca06

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
@@ -13,7 +13,7 @@
1313
import tempfile
1414
from functools import partial
1515
from pkgutil import ModuleInfo
16-
from unittest import TestCase, skipUnless, skipIf, SkipTest
16+
from unittest import TestCase, skipUnless, SkipTest
1717
from unittest.mock import Mock, patch
1818
import warnings
1919
from test.support import (
@@ -37,6 +37,7 @@
3737
code_to_events,
3838
)
3939
from _colorize import ANSIColors, get_theme
40+
from _pyrepl import terminfo
4041
from _pyrepl.console import Event
4142
from _pyrepl.completing_reader import stripcolor
4243
from _pyrepl._module_completer import (
@@ -1998,8 +1999,20 @@ def test_dumb_terminal_exits_cleanly(self):
19981999
self.assertNotIn("Traceback", output)
19992000

20002001

2002+
def supports_pyrepl():
2003+
# pyrepl falls back to the basic REPL if the terminal lacks any of the
2004+
# capabilities which UnixConsole requires. This covers an unset or
2005+
# "dumb" TERM as well, they are resolved to the "dumb" capabilities.
2006+
try:
2007+
info = terminfo.TermInfo(None)
2008+
except Exception:
2009+
return False
2010+
return all(info.get(cap) is not None
2011+
for cap in ("bel", "clear", "cup", "el"))
2012+
2013+
20012014
@skipUnless(pty, "requires pty")
2002-
@skipIf((os.environ.get("TERM") or "dumb") == "dumb", "can't use pyrepl in dumb terminal")
2015+
@skipUnless(supports_pyrepl(), "can't use pyrepl in this terminal")
20032016
class TestMain(ReplTestCase):
20042017
def setUp(self):
20052018
# Cleanup from PYTHON* variables to isolate from local

0 commit comments

Comments
 (0)