mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
[3.13] gh-87320: In the code module, handle exceptions raised in sys.excepthook (GH-122456) (GH-122514)
Before, the exception caused by calling non-default sys.excepthook
in code.InteractiveInterpreter bubbled up to the caller, ending the REPL.
(cherry picked from commit bd3d31f380
)
Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
This commit is contained in:
parent
1fd1c6c738
commit
84c8cd0f3d
4 changed files with 76 additions and 3 deletions
|
@ -1049,6 +1049,30 @@ class TestMain(TestCase):
|
|||
self.assertNotIn("Exception", output)
|
||||
self.assertNotIn("Traceback", output)
|
||||
|
||||
@force_not_colorized
|
||||
def test_bad_sys_excepthook_doesnt_crash_pyrepl(self):
|
||||
env = os.environ.copy()
|
||||
commands = ("import sys\n"
|
||||
"sys.excepthook = 1\n"
|
||||
"1/0\n"
|
||||
"exit()\n")
|
||||
|
||||
def check(output, exitcode):
|
||||
self.assertIn("Error in sys.excepthook:", output)
|
||||
self.assertEqual(output.count("'int' object is not callable"), 1)
|
||||
self.assertIn("Original exception was:", output)
|
||||
self.assertIn("division by zero", output)
|
||||
self.assertEqual(exitcode, 0)
|
||||
env.pop("PYTHON_BASIC_REPL", None)
|
||||
output, exit_code = self.run_repl(commands, env=env)
|
||||
if "can\'t use pyrepl" in output:
|
||||
self.skipTest("pyrepl not available")
|
||||
check(output, exit_code)
|
||||
|
||||
env["PYTHON_BASIC_REPL"] = "1"
|
||||
output, exit_code = self.run_repl(commands, env=env)
|
||||
check(output, exit_code)
|
||||
|
||||
def test_not_wiping_history_file(self):
|
||||
# skip, if readline module is not available
|
||||
import_module('readline')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue