Skip to content

Commit 278b289

Browse files
authored
Merge pull request #4968 from blueyed/pdb-do_debug-quit
pdb: do not raise outcomes.Exit with quit in debug
2 parents e7ade06 + 4011021 commit 278b289

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
@@ -176,8 +176,15 @@ def do_continue(self, arg):
176176
do_c = do_cont = do_continue
177177

178178
def set_quit(self):
179+
"""Raise Exit outcome when quit command is used in pdb.
180+
181+
This is a bit of a hack - it would be better if BdbQuit
182+
could be handled, but this would require to wrap the
183+
whole pytest run, and adjust the report etc.
184+
"""
179185
super(_PdbWrapper, self).set_quit()
180-
outcomes.exit("Quitting debugger")
186+
if cls._recursive_debug == 0:
187+
outcomes.exit("Quitting debugger")
181188

182189
def setup(self, f, tb):
183190
"""Suspend on setup().

testing/test_pdb.py

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

522-
def test_pdb_interaction_continue_recursive(self, testdir):
522+
def test_pdb_with_injected_do_debug(self, testdir):
523+
"""Simulates pdbpp, which injects Pdb into do_debug, and uses
524+
self.__class__ in do_continue.
525+
"""
523526
p1 = testdir.makepyfile(
524527
mytest="""
525528
import pdb
526529
import pytest
527530
528531
count_continue = 0
529532
530-
# Simulates pdbpp, which injects Pdb into do_debug, and uses
531-
# self.__class__ in do_continue.
532533
class CustomPdb(pdb.Pdb, object):
533534
def do_debug(self, arg):
534535
import sys
@@ -578,6 +579,14 @@ def test_1():
578579
assert b"PDB continue" not in child.before
579580
# No extra newline.
580581
assert child.before.endswith(b"c\r\nprint_from_foo\r\n")
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)