Skip to content

Commit b44f479

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

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,3 +954,30 @@ def test_2():
954954
rest = child.read().decode("utf8")
955955
assert "no tests ran" in rest
956956
TestPDB.flush(child)
957+
958+
959+
def test_pdb_quit_after_debug(testdir):
960+
p1 = testdir.makepyfile(
961+
mytest="""
962+
def foo():
963+
pass
964+
965+
def test_1():
966+
__import__('pdb').set_trace()
967+
"""
968+
)
969+
child = testdir.spawn_pytest(str(p1))
970+
child.expect(r"\n\(Pdb")
971+
child.sendline("debug foo()")
972+
child.expect("ENTERING RECURSIVE DEBUGGER")
973+
child.expect(r"\n\(\(Pdb")
974+
child.sendline("q")
975+
child.expect("LEAVING RECURSIVE DEBUGGER")
976+
assert b"Quitting debugger" not in child.before
977+
child.sendline("q")
978+
rest = child.read().decode("utf8")
979+
# NOTE: there should be less trailing newlines with this probably, but
980+
# this tests the current behavior.
981+
assert "\r\nExit: Quitting debugger\r\n\r\n\r\n"
982+
assert "! _pytest.outcomes.Exit: Quitting debugger !" in rest
983+
assert "= no tests ran in " in rest

0 commit comments

Comments
 (0)