From f1c53a16f0937195f47761bbf1ff15d879bc009a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 9 May 2019 00:06:36 +0200 Subject: [PATCH] pdb: only use outcomes.exit via do_quit Fixes https://github.com/pytest-dev/pytest/issues/5235. --- changelog/5235.bugfix.rst | 1 + src/_pytest/debugging.py | 10 ++++++++-- testing/test_pdb.py | 29 +++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 changelog/5235.bugfix.rst diff --git a/changelog/5235.bugfix.rst b/changelog/5235.bugfix.rst new file mode 100644 index 00000000000..87597a589d5 --- /dev/null +++ b/changelog/5235.bugfix.rst @@ -0,0 +1 @@ +``outcome.exit`` is not used with ``EOF`` in the pdb wrapper anymore, but only with ``quit``. diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index 7138fd2e158..52c6536f4dc 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -181,17 +181,23 @@ def do_continue(self, arg): 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(). diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 0a72a290769..f28b5fc6ede 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -395,7 +395,7 @@ def test_1(): 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 +957,7 @@ def test_1(): 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 +1163,28 @@ def runcall(self, *args, **kwds): ) assert result.ret == 0 result.stdout.fnmatch_lines(["*runcall_called*", "* 1 passed in *"]) + + +def test_pdb_eoferror_without_read(testdir): + p1 = testdir.makepyfile( + """ + + def input_without_read(*args, **kwargs): + raise EOFError() + + + def test(monkeypatch): + try: + import __builtin__ + except ImportError: + import builtins + monkeypatch.setattr(builtins, "input", input_without_read) + else: + monkeypatch.setattr(__builtin__, "raw_input", input_without_read) + + __import__('pdb').set_trace() + """ + ) + result = testdir.runpytest(str(p1)) + result.stdout.fnmatch_lines(["E *BdbQuit", "*= 1 failed in*"]) + assert result.ret == 1