Merge pull request #4968 from blueyed/pdb-do_debug-quit

pdb: do not raise outcomes.Exit with quit in debug
This commit is contained in:
Bruno Oliveira 2019-03-29 16:22:02 -03:00 committed by GitHub
commit 278b289f37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 4 deletions

View File

@ -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/

View File

@ -176,7 +176,14 @@ class pytestPDB(object):
do_c = do_cont = do_continue do_c = do_cont = do_continue
def set_quit(self): 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() super(_PdbWrapper, self).set_quit()
if cls._recursive_debug == 0:
outcomes.exit("Quitting debugger") outcomes.exit("Quitting debugger")
def setup(self, f, tb): def setup(self, f, tb):

View File

@ -519,7 +519,10 @@ class TestPDB(object):
assert "1 failed" in rest assert "1 failed" in rest
self.flush(child) 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( p1 = testdir.makepyfile(
mytest=""" mytest="""
import pdb import pdb
@ -527,8 +530,6 @@ class TestPDB(object):
count_continue = 0 count_continue = 0
# Simulates pdbpp, which injects Pdb into do_debug, and uses
# self.__class__ in do_continue.
class CustomPdb(pdb.Pdb, object): class CustomPdb(pdb.Pdb, object):
def do_debug(self, arg): def do_debug(self, arg):
import sys import sys
@ -578,6 +579,14 @@ class TestPDB(object):
assert b"PDB continue" not in child.before assert b"PDB continue" not in child.before
# No extra newline. # No extra newline.
assert child.before.endswith(b"c\r\nprint_from_foo\r\n") assert child.before.endswith(b"c\r\nprint_from_foo\r\n")
# 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.sendline("c")
child.expect(r"PDB continue \(IO-capturing resumed\)") child.expect(r"PDB continue \(IO-capturing resumed\)")
rest = child.read().decode("utf8") rest = child.read().decode("utf8")