From 2e576409922e395e027a8dfda610a942c0f60f08 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 21 Mar 2019 07:22:15 +0100 Subject: [PATCH] pdb: do not raise outcomes.Exit with quit in debug --- changelog/4968.bugfix.rst | 1 + src/_pytest/debugging.py | 9 ++++++++- testing/test_pdb.py | 27 +++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 changelog/4968.bugfix.rst diff --git a/changelog/4968.bugfix.rst b/changelog/4968.bugfix.rst new file mode 100644 index 00000000000..9c46f60775b --- /dev/null +++ b/changelog/4968.bugfix.rst @@ -0,0 +1 @@ +The pdb ``quit`` command is handled properly when used after the ``debug`` command. diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index 6b401aa0bdc..1379193cfe8 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -128,8 +128,15 @@ def do_continue(self, arg): do_c = do_cont = do_continue def set_quit(self): + """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(_PdbWrapper, self).set_quit() - outcomes.exit("Quitting debugger") + if cls._recursive_debug == 0: + outcomes.exit("Quitting debugger") def setup(self, f, tb): """Suspend on setup(). diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 68cb1cf0057..159f51d6d45 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -954,3 +954,30 @@ def test_2(): rest = child.read().decode("utf8") assert "no tests ran" in rest TestPDB.flush(child) + + +def test_pdb_quit_after_debug(testdir): + p1 = testdir.makepyfile( + mytest=""" + def foo(): + pass + + def test_1(): + __import__('pdb').set_trace() + """ + ) + child = testdir.spawn_pytest(str(p1)) + child.expect(r"\n\(Pdb") + child.sendline("debug foo()") + child.expect("ENTERING RECURSIVE DEBUGGER") + child.expect(r"\n\(\(Pdb") + child.sendline("q") + child.expect("LEAVING RECURSIVE DEBUGGER") + assert b"Quitting debugger" not in child.before + child.sendline("q") + rest = child.read().decode("utf8") + # NOTE: there should be less trailing newlines with this probably, but + # this tests the current behavior. + assert "\r\nExit: Quitting debugger\r\n\r\n\r\n" + assert " Quitting debugger !" in rest + assert "= no tests ran in " in rest