mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-82378 fix sys.tracebacklimit in pyrepl, approach 2 (#123062)
Make sure that pyrepl uses the same logic for sys.tracebacklimit as both the basic repl and the standard sys.excepthook
This commit is contained in:
parent
79c542b5cc
commit
63603bca35
4 changed files with 54 additions and 16 deletions
|
@ -1020,7 +1020,7 @@ class TestMain(TestCase):
|
|||
env.update({"TERM": "dumb"})
|
||||
output, exit_code = self.run_repl("exit()\n", env=env)
|
||||
self.assertEqual(exit_code, 0)
|
||||
self.assertIn("warning: can\'t use pyrepl", output)
|
||||
self.assertIn("warning: can't use pyrepl", output)
|
||||
self.assertNotIn("Exception", output)
|
||||
self.assertNotIn("Traceback", output)
|
||||
|
||||
|
@ -1100,6 +1100,38 @@ class TestMain(TestCase):
|
|||
self.assertIn("spam", output)
|
||||
self.assertNotEqual(pathlib.Path(hfile.name).stat().st_size, 0)
|
||||
|
||||
@force_not_colorized
|
||||
def test_proper_tracebacklimit(self):
|
||||
env = os.environ.copy()
|
||||
for set_tracebacklimit in [True, False]:
|
||||
commands = ("import sys\n" +
|
||||
("sys.tracebacklimit = 1\n" if set_tracebacklimit else "") +
|
||||
"def x1(): 1/0\n\n"
|
||||
"def x2(): x1()\n\n"
|
||||
"def x3(): x2()\n\n"
|
||||
"x3()\n"
|
||||
"exit()\n")
|
||||
|
||||
for basic_repl in [True, False]:
|
||||
if basic_repl:
|
||||
env["PYTHON_BASIC_REPL"] = "1"
|
||||
else:
|
||||
env.pop("PYTHON_BASIC_REPL", None)
|
||||
with self.subTest(set_tracebacklimit=set_tracebacklimit,
|
||||
basic_repl=basic_repl):
|
||||
output, exit_code = self.run_repl(commands, env=env)
|
||||
if "can't use pyrepl" in output:
|
||||
self.skipTest("pyrepl not available")
|
||||
self.assertIn("in x1", output)
|
||||
if set_tracebacklimit:
|
||||
self.assertNotIn("in x2", output)
|
||||
self.assertNotIn("in x3", output)
|
||||
self.assertNotIn("in <module>", output)
|
||||
else:
|
||||
self.assertIn("in x2", output)
|
||||
self.assertIn("in x3", output)
|
||||
self.assertIn("in <module>", output)
|
||||
|
||||
def run_repl(
|
||||
self,
|
||||
repl_input: str | list[str],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue