Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
ADThomas-astro committed Feb 7, 2025
commit d6db1b0acfe350e5547e161516f7f1fadc746c86
10 changes: 2 additions & 8 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,7 @@ def set_trace(self, frame=None, *, commands=None):
if commands is not None:
self.rcLines.extend(commands)

try:
super().set_trace(frame)
except bdb.BdbQuit: # Make stacktrace shorter
raise bdb.BdbQuit from None
super().set_trace(frame)

def sigint_handler(self, signum, frame):
if self.allow_kbdint:
Expand Down Expand Up @@ -2396,10 +2393,7 @@ def set_trace(*, header=None, commands=None):
pdb = Pdb(mode='inline')
if header is not None:
pdb.message(header)
try:
pdb.set_trace(sys._getframe().f_back, commands=commands)
except bdb.BdbQuit: # Make stacktrace shorter
raise bdb.BdbQuit from None
pdb.set_trace(sys._getframe().f_back, commands=commands)

# Post-Mortem interface

Expand Down
31 changes: 26 additions & 5 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4274,23 +4274,44 @@ def _run_script(self, script, commands,
)
return stdout, stderr

def test_quit(self):
def test_quit_with_BdbQuit(self):
# Test quitting with a bdb.BdbQuit exception, which allows control to
# return to the repl.
script = """
x = 1
breakpoint()
"""

commands = """
exit
c
p x + 1
quit
n
e
"""

stdout, stderr = self._run_script(script, commands, expected_returncode=1)
self.assertIn("2", stdout)
self.assertIn("Exit pdb? [e/k/c]", stdout)
self.assertIn("BdbQuit", stderr)

def test_quit_abort_process(self):
script = """
x = 1
breakpoint()
"""

commands = """
exit
c
p x + 1
quit
y
k
"""

stdout, stderr = self._run_script(script, commands)
stdout, stderr = self._run_script(script, commands, expected_returncode=0)
self.assertIn("2", stdout)
self.assertIn("Quit anyway", stdout)
self.assertIn("Exit pdb? [e/k/c]", stdout)


@support.requires_subprocess()
Expand Down