mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-124703: Change back to raising bdb.BdbQuit when exiting pdb in 'inline' mode in a REPL session (#130395)
This commit is contained in:
parent
3a555f09f3
commit
ccb4ad9219
3 changed files with 29 additions and 1 deletions
|
@ -1758,7 +1758,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
|
||||
Quit from the debugger. The program being executed is aborted.
|
||||
"""
|
||||
if self.mode == 'inline':
|
||||
# Show prompt to kill process when in 'inline' mode and if pdb was not
|
||||
# started from an interactive console. The attribute sys.ps1 is only
|
||||
# defined if the interpreter is in interactive mode.
|
||||
if self.mode == 'inline' and not hasattr(sys, 'ps1'):
|
||||
while True:
|
||||
try:
|
||||
reply = input('Quitting pdb will kill the process. Quit anyway? [y/n] ')
|
||||
|
|
|
@ -19,6 +19,7 @@ from test import support
|
|||
from test.support import force_not_colorized, os_helper
|
||||
from test.support.import_helper import import_module
|
||||
from test.support.pty_helper import run_pty, FakeInput
|
||||
from test.support.script_helper import kill_python
|
||||
from unittest.mock import patch
|
||||
|
||||
SKIP_CORO_TESTS = False
|
||||
|
@ -4342,6 +4343,29 @@ class PdbTestInline(unittest.TestCase):
|
|||
self.assertEqual(stdout.count("Quit anyway"), 2)
|
||||
|
||||
|
||||
@support.force_not_colorized_test_class
|
||||
@support.requires_subprocess()
|
||||
class TestREPLSession(unittest.TestCase):
|
||||
def test_return_from_inline_mode_to_REPL(self):
|
||||
# GH-124703: Raise BdbQuit when exiting pdb in REPL session.
|
||||
# This allows the REPL session to continue.
|
||||
from test.test_repl import spawn_repl
|
||||
p = spawn_repl()
|
||||
user_input = """
|
||||
x = 'Spam'
|
||||
import pdb
|
||||
pdb.set_trace(commands=['x + "During"', 'q'])
|
||||
x + 'After'
|
||||
"""
|
||||
p.stdin.write(textwrap.dedent(user_input))
|
||||
output = kill_python(p)
|
||||
self.assertIn('SpamDuring', output)
|
||||
self.assertNotIn("Quit anyway", output)
|
||||
self.assertIn('BdbQuit', output)
|
||||
self.assertIn('SpamAfter', output)
|
||||
self.assertEqual(p.returncode, 0)
|
||||
|
||||
|
||||
@support.requires_subprocess()
|
||||
class PdbTestReadline(unittest.TestCase):
|
||||
def setUpClass():
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Executing ``quit`` command in :mod:`pdb` will raise :exc:`bdb.BdbQuit` when :mod:`pdb` is started from an interactive console using :func:`breakpoint` or :func:`pdb.set_trace`.
|
Loading…
Add table
Add a link
Reference in a new issue