Skip to content

Commit facad4e

Browse files
committed
pdb: do not raise outcomes.Exit with quit in debug
1 parent 7764312 commit facad4e

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

changelog/4968.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The pdb ``quit`` command is handled properly when used after the ``debug`` command with `pdb++`_.
2+
3+
.. _pdb++: https://pypi.org/project/pdbpp/

src/_pytest/debugging.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,15 @@ def do_continue(self, arg):
128128
do_c = do_cont = do_continue
129129

130130
def set_quit(self):
131+
"""Raise Exit outcome when quit command is used in pdb.
132+
133+
This is a bit of a hack - it would be better if BdbQuit
134+
could be handled, but this would require to wrap the
135+
whole pytest run, and adjust the report etc.
136+
"""
131137
super(_PdbWrapper, self).set_quit()
132-
outcomes.exit("Quitting debugger")
138+
if cls._recursive_debug == 0:
139+
outcomes.exit("Quitting debugger")
133140

134141
def setup(self, f, tb):
135142
"""Suspend on setup().

testing/test_pdb.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,16 +520,17 @@ def test_1():
520520
assert "1 failed" in rest
521521
self.flush(child)
522522

523-
def test_pdb_interaction_continue_recursive(self, testdir):
523+
def test_pdb_with_injected_do_debug(self, testdir):
524+
"""Simulates pdbpp, which injects Pdb into do_debug, and uses
525+
self.__class__ in do_continue.
526+
"""
524527
p1 = testdir.makepyfile(
525528
mytest="""
526529
import pdb
527530
import pytest
528531
529532
count_continue = 0
530533
531-
# Simulates pdbpp, which injects Pdb into do_debug, and uses
532-
# self.__class__ in do_continue.
533534
class CustomPdb(pdb.Pdb, object):
534535
def do_debug(self, arg):
535536
import sys
@@ -578,6 +579,14 @@ def test_1():
578579
child.expect("LEAVING RECURSIVE DEBUGGER")
579580
assert b"PDB continue" not in child.before
580581
assert b"print_from_foo" in child.before
582+
583+
# set_debug should not raise outcomes.Exit, if used recrursively.
584+
child.sendline("debug 42")
585+
child.sendline("q")
586+
child.expect("LEAVING RECURSIVE DEBUGGER")
587+
assert b"ENTERING RECURSIVE DEBUGGER" in child.before
588+
assert b"Quitting debugger" not in child.before
589+
581590
child.sendline("c")
582591
child.expect(r"PDB continue \(IO-capturing resumed\)")
583592
rest = child.read().decode("utf8")

0 commit comments

Comments
 (0)