Merge pull request #5236 from blueyed/pdb-eoferror-quit

pdb: only use outcomes.exit via do_quit
This commit is contained in:
Daniel Hahler 2019-05-09 17:10:36 +02:00 committed by GitHub
commit ceca35b94a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 4 deletions

View File

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

View File

@ -181,17 +181,23 @@ class pytestPDB(object):
do_c = do_cont = do_continue
def set_quit(self):
def do_quit(self, arg):
"""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(PytestPdbWrapper, self).set_quit()
ret = super(PytestPdbWrapper, self).do_quit(arg)
if cls._recursive_debug == 0:
outcomes.exit("Quitting debugger")
return ret
do_q = do_quit
do_exit = do_quit
def setup(self, f, tb):
"""Suspend on setup().

View File

@ -6,6 +6,8 @@ import os
import platform
import sys
import six
import _pytest._code
import pytest
from _pytest.debugging import _validate_usepdb_cls
@ -395,7 +397,7 @@ class TestPDB(object):
child = testdir.spawn_pytest(str(p1))
child.expect("test_1")
child.expect("Pdb")
child.sendeof()
child.sendline("q")
rest = child.read().decode("utf8")
assert "no tests ran" in rest
assert "reading from stdin while output" not in rest
@ -957,7 +959,7 @@ class TestDebuggingBreakpoints(object):
child = testdir.spawn_pytest(str(p1))
child.expect("test_1")
child.expect("Pdb")
child.sendeof()
child.sendline("quit")
rest = child.read().decode("utf8")
assert "Quitting debugger" in rest
assert "reading from stdin while output" not in rest
@ -1163,3 +1165,29 @@ def test_pdbcls_via_local_module(testdir):
)
assert result.ret == 0
result.stdout.fnmatch_lines(["*runcall_called*", "* 1 passed in *"])
def test_raises_bdbquit_with_eoferror(testdir):
"""It is not guaranteed that DontReadFromInput's read is called."""
if six.PY2:
builtin_module = "__builtin__"
input_func = "raw_input"
else:
builtin_module = "builtins"
input_func = "input"
p1 = testdir.makepyfile(
"""
def input_without_read(*args, **kwargs):
raise EOFError()
def test(monkeypatch):
import {builtin_module}
monkeypatch.setattr({builtin_module}, {input_func!r}, input_without_read)
__import__('pdb').set_trace()
""".format(
builtin_module=builtin_module, input_func=input_func
)
)
result = testdir.runpytest(str(p1))
result.stdout.fnmatch_lines(["E *BdbQuit", "*= 1 failed in*"])
assert result.ret == 1