Skip to content

Commit 73b74c7

Browse files
committed
pdb: only use outcomes.exit via do_quit
Fixes #5235.
1 parent 5eeb5ee commit 73b74c7

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

changelog/5235.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``outcome.exit`` is not used with ``EOF`` in the pdb wrapper anymore, but only with ``quit``.

src/_pytest/debugging.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,23 @@ def do_continue(self, arg):
181181

182182
do_c = do_cont = do_continue
183183

184-
def set_quit(self):
184+
def do_quit(self, arg):
185185
"""Raise Exit outcome when quit command is used in pdb.
186186
187187
This is a bit of a hack - it would be better if BdbQuit
188188
could be handled, but this would require to wrap the
189189
whole pytest run, and adjust the report etc.
190190
"""
191-
super(PytestPdbWrapper, self).set_quit()
191+
ret = super(PytestPdbWrapper, self).do_quit(arg)
192+
192193
if cls._recursive_debug == 0:
193194
outcomes.exit("Quitting debugger")
194195

196+
return ret
197+
198+
do_q = do_quit
199+
do_exit = do_quit
200+
195201
def setup(self, f, tb):
196202
"""Suspend on setup().
197203

testing/test_pdb.py

+30-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import platform
77
import sys
88

9+
import six
10+
911
import _pytest._code
1012
import pytest
1113
from _pytest.debugging import _validate_usepdb_cls
@@ -395,7 +397,7 @@ def test_1():
395397
child = testdir.spawn_pytest(str(p1))
396398
child.expect("test_1")
397399
child.expect("Pdb")
398-
child.sendeof()
400+
child.sendline("q")
399401
rest = child.read().decode("utf8")
400402
assert "no tests ran" in rest
401403
assert "reading from stdin while output" not in rest
@@ -957,7 +959,7 @@ def test_1():
957959
child = testdir.spawn_pytest(str(p1))
958960
child.expect("test_1")
959961
child.expect("Pdb")
960-
child.sendeof()
962+
child.sendline("quit")
961963
rest = child.read().decode("utf8")
962964
assert "Quitting debugger" in rest
963965
assert "reading from stdin while output" not in rest
@@ -1163,3 +1165,29 @@ def runcall(self, *args, **kwds):
11631165
)
11641166
assert result.ret == 0
11651167
result.stdout.fnmatch_lines(["*runcall_called*", "* 1 passed in *"])
1168+
1169+
1170+
def test_raises_bdbquit_with_eoferror(testdir):
1171+
"""It is not guaranteed that DontReadFromInput's read is called."""
1172+
if six.PY2:
1173+
builtin_module = "__builtin__"
1174+
input_func = "raw_input"
1175+
else:
1176+
builtin_module = "builtins"
1177+
input_func = "input"
1178+
p1 = testdir.makepyfile(
1179+
"""
1180+
def input_without_read(*args, **kwargs):
1181+
raise EOFError()
1182+
1183+
def test(monkeypatch):
1184+
import {builtin_module}
1185+
monkeypatch.setattr({builtin_module}, {input_func!r}, input_without_read)
1186+
__import__('pdb').set_trace()
1187+
""".format(
1188+
builtin_module=builtin_module, input_func=input_func
1189+
)
1190+
)
1191+
result = testdir.runpytest(str(p1))
1192+
result.stdout.fnmatch_lines(["E *BdbQuit", "*= 1 failed in*"])
1193+
assert result.ret == 1

0 commit comments

Comments
 (0)