Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1758,7 +1758,8 @@ def do_quit(self, arg):

Quit from the debugger. The program being executed is aborted.
"""
if self.mode == 'inline':
in_repl_session = hasattr(sys, 'ps1')
if self.mode == 'inline' and not in_repl_session:
while True:
try:
reply = input('Quitting pdb will kill the process. Quit anyway? [y/n] ')
Expand Down
40 changes: 40 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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
Expand Down Expand Up @@ -4342,6 +4343,45 @@ def test_quit(self):
self.assertEqual(stdout.count("Quit anyway"), 2)


def spawn_repl():
"""Run the basic Python REPL. Returns a Popen object."""
# This function is based on the function "spawn_repl" in test_repl.py.
# See comments there for the rationale for the command line args.
stdin_fname = os.path.join(os.path.dirname(sys.executable), '<stdin>')
proc = subprocess.Popen(
[stdin_fname, '-I', '-i'],
env={'PYTHON_BASIC_REPL': '1'},
executable=sys.executable,
text=True,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
return proc


@support.force_not_colorized_test_class
@support.requires_subprocess()
class TestREPLSession(unittest.TestCase):
def test_return_from_inline_mode_to_REPL(self):
# Issue #124703: Raise BdbQuit when exiting pdb in REPL session.
# This allows the REPL session to continue.
user_input = """
x = 'Spam'
import pdb
pdb.set_trace(commands=['x * 3', 'q'])
print('Afterward')
"""
p = spawn_repl()
p.stdin.write(textwrap.dedent(user_input))
output = kill_python(p)
self.assertIn('SpamSpamSpam', output)
self.assertNotIn('Quit anyway', output)
self.assertIn('BdbQuit', output)
self.assertIn('Afterward', output)
self.assertEqual(p.returncode, 0)


@support.requires_subprocess()
class PdbTestReadline(unittest.TestCase):
def setUpClass():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restore the ability to easily return to the REPL from a pdb session after calling ``breakpoint`` or ``set_trace``.
Loading