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 21, 2019
1 parent 7764312 commit 2e57640
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog/4968.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The pdb ``quit`` command is handled properly when used after the ``debug`` command.
9 changes: 8 additions & 1 deletion src/_pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,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
27 changes: 27 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,3 +954,30 @@ def test_2():
rest = child.read().decode("utf8")
assert "no tests ran" in rest
TestPDB.flush(child)


def test_pdb_quit_after_debug(testdir):
p1 = testdir.makepyfile(
mytest="""
def foo():
pass
def test_1():
__import__('pdb').set_trace()
"""
)
child = testdir.spawn_pytest(str(p1))
child.expect(r"\n\(Pdb")
child.sendline("debug foo()")
child.expect("ENTERING RECURSIVE DEBUGGER")
child.expect(r"\n\(\(Pdb")
child.sendline("q")
child.expect("LEAVING RECURSIVE DEBUGGER")
assert b"Quitting debugger" not in child.before
child.sendline("q")
rest = child.read().decode("utf8")
# NOTE: there should be less trailing newlines with this probably, but
# this tests the current behavior.
assert "\r\nExit: Quitting debugger\r\n\r\n\r\n"
assert " Quitting debugger !" in rest
assert "= no tests ran in " in rest

0 comments on commit 2e57640

Please sign in to comment.