Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/_pytest/debugging.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
""" interactive debugging with PDB, the Python Debugger. """
from __future__ import absolute_import, division, print_function

import os
import pdb
import sys
import os
from doctest import UnexpectedException

from _pytest import outcomes
from _pytest.config import hookimpl

try:
Expand Down Expand Up @@ -164,8 +166,9 @@ def _enter_pdb(node, excinfo, rep):
rep.toterminal(tw)
tw.sep(">", "entering PDB")
tb = _postmortem_traceback(excinfo)
post_mortem(tb)
rep._pdbshown = True
if post_mortem(tb):
outcomes.exit("Quitting debugger")
return rep


Expand Down Expand Up @@ -196,3 +199,4 @@ def get_stack(self, f, t):
p = Pdb()
p.reset()
p.interaction(None, t)
return p.quitting
15 changes: 12 additions & 3 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def custom_pdb_calls():

# install dummy debugger class and track which methods were called on it
class _CustomPdb(object):
quitting = False

def __init__(self, *args, **kwargs):
called.append("init")

Expand Down Expand Up @@ -142,6 +144,9 @@ def test_pdb_interaction(self, testdir):
def test_1():
i = 0
assert i == 1

def test_not_called_due_to_quit():
pass
"""
)
child = testdir.spawn_pytest("--pdb %s" % p1)
Expand All @@ -150,8 +155,9 @@ def test_1():
child.expect("Pdb")
child.sendeof()
rest = child.read().decode("utf8")
assert "1 failed" in rest
assert "= 1 failed in" in rest
assert "def test_1" not in rest
assert "Exit: Quitting debugger" in rest
self.flush(child)

@staticmethod
Expand Down Expand Up @@ -321,7 +327,7 @@ def test_pdb_interaction_on_collection_issue181(self, testdir):
child = testdir.spawn_pytest("--pdb %s" % p1)
# child.expect(".*import pytest.*")
child.expect("Pdb")
child.sendeof()
child.sendline("c")
child.expect("1 error")
self.flush(child)

Expand Down Expand Up @@ -376,6 +382,7 @@ def test_1():
rest = child.read().decode("utf8")
assert "1 failed" in rest
assert "reading from stdin while output" not in rest
assert "BdbQuit" in rest
self.flush(child)

def test_pdb_and_capsys(self, testdir):
Expand Down Expand Up @@ -518,7 +525,9 @@ def test_foo(a):
def test_pdb_collection_failure_is_shown(self, testdir):
p1 = testdir.makepyfile("xxx")
result = testdir.runpytest_subprocess("--pdb", p1)
result.stdout.fnmatch_lines(["*NameError*xxx*", "*1 error*"])
result.stdout.fnmatch_lines(
["E NameError: *xxx*", "*! *Exit: Quitting debugger !*"] # due to EOF
)

def test_enter_pdb_hook_is_called(self, testdir):
testdir.makeconftest(
Expand Down