Skip to content

Commit 77b51b0

Browse files
committed
Handle quitting from pdb with --trace
1 parent 233c2a2 commit 77b51b0

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/_pytest/debugging.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ def do_continue(self, arg):
101101

102102
do_c = do_cont = do_continue
103103

104+
def set_quit(self):
105+
super(_PdbWrapper, self).set_quit()
106+
outcomes.exit("Quitting debugger")
107+
104108
def setup(self, f, tb):
105109
"""Suspend on setup().
106110
@@ -122,6 +126,7 @@ def setup(self, f, tb):
122126

123127
if set_break:
124128
_pdb.set_trace(frame)
129+
return _pdb
125130

126131

127132
class PdbInvoke(object):
@@ -147,9 +152,9 @@ def pytest_pyfunc_call(self, pyfuncitem):
147152

148153

149154
def _test_pytest_function(pyfuncitem):
150-
pytestPDB.set_trace(set_break=False)
155+
_pdb = pytestPDB.set_trace(set_break=False)
151156
testfunction = pyfuncitem.obj
152-
pyfuncitem.obj = pdb.runcall
157+
pyfuncitem.obj = _pdb.runcall
153158
if pyfuncitem._isyieldedfunction():
154159
arg_list = list(pyfuncitem._args)
155160
arg_list.insert(0, testfunction)

testing/test_pdb.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,15 +781,26 @@ def test_trace_sets_breakpoint(self, testdir):
781781
"""
782782
def test_1():
783783
assert True
784+
785+
def test_2():
786+
pass
787+
788+
def test_3():
789+
pass
784790
"""
785791
)
786792
child = testdir.spawn_pytest("--trace " + str(p1))
787793
child.expect("test_1")
788794
child.expect("Pdb")
789-
child.sendeof()
795+
child.sendline("c")
796+
child.expect("test_2")
797+
child.expect("Pdb")
798+
child.sendline("q")
799+
child.expect_exact("Exit: Quitting debugger")
790800
rest = child.read().decode("utf8")
791-
assert "1 passed" in rest
801+
assert "1 passed in" in rest
792802
assert "reading from stdin while output" not in rest
803+
assert "Exit: Quitting debugger" in child.before.decode("utf8")
793804
TestPDB.flush(child)
794805

795806
def test_trace_against_yield_test(self, testdir):

0 commit comments

Comments
 (0)