Skip to content

Commit

Permalink
pdb: do not raise outcomes.Exit with quit in debug
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Mar 27, 2019
1 parent 69a55d3 commit f38c512
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions changelog/4968.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The pdb ``quit`` command is handled properly when used after the ``debug`` command with `pdb++`_.

.. _pdb++: https://pypi.org/project/pdbpp/
9 changes: 8 additions & 1 deletion src/_pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,15 @@ def do_continue(self, arg):
do_c = do_cont = do_continue

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

def setup(self, f, tb):
"""Suspend on setup().
Expand Down
15 changes: 12 additions & 3 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,16 +519,17 @@ def test_1():
assert "1 failed" in rest
self.flush(child)

def test_pdb_interaction_continue_recursive(self, testdir):
def test_pdb_with_injected_do_debug(self, testdir):
"""Simulates pdbpp, which injects Pdb into do_debug, and uses
self.__class__ in do_continue.
"""
p1 = testdir.makepyfile(
mytest="""
import pdb
import pytest
count_continue = 0
# Simulates pdbpp, which injects Pdb into do_debug, and uses
# self.__class__ in do_continue.
class CustomPdb(pdb.Pdb, object):
def do_debug(self, arg):
import sys
Expand Down Expand Up @@ -577,6 +578,14 @@ def test_1():
child.expect("LEAVING RECURSIVE DEBUGGER")
assert b"PDB continue" not in child.before
assert b"print_from_foo" in child.before

# set_debug should not raise outcomes.Exit, if used recrursively.
child.sendline("debug 42")
child.sendline("q")
child.expect("LEAVING RECURSIVE DEBUGGER")
assert b"ENTERING RECURSIVE DEBUGGER" in child.before
assert b"Quitting debugger" not in child.before

child.sendline("c")
child.expect(r"PDB continue \(IO-capturing resumed\)")
rest = child.read().decode("utf8")
Expand Down

0 comments on commit f38c512

Please sign in to comment.