diff --git a/changelog/4132.bugfix.rst b/changelog/4132.bugfix.rst new file mode 100644 index 000000000..1fbb9afad --- /dev/null +++ b/changelog/4132.bugfix.rst @@ -0,0 +1 @@ +Fix duplicate printing of internal errors when using ``--pdb``. diff --git a/src/_pytest/debugging.py b/src/_pytest/debugging.py index f51dff373..d9a6a8154 100644 --- a/src/_pytest/debugging.py +++ b/src/_pytest/debugging.py @@ -109,9 +109,6 @@ class PdbInvoke(object): _enter_pdb(node, call.excinfo, report) def pytest_internalerror(self, excrepr, excinfo): - for line in str(excrepr).split("\n"): - sys.stderr.write("INTERNALERROR> %s\n" % line) - sys.stderr.flush() tb = _postmortem_traceback(excinfo) post_mortem(tb) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index f04a2f3a0..cda553c44 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -334,8 +334,12 @@ class TestPDB(object): ) p1 = testdir.makepyfile("def test_func(): pass") child = testdir.spawn_pytest("--pdb %s" % p1) - # child.expect(".*import pytest.*") child.expect("Pdb") + + # INTERNALERROR is only displayed once via terminal reporter. + assert len([x for x in child.before.decode().splitlines() + if x.startswith("INTERNALERROR> Traceback")]) == 1 + child.sendeof() self.flush(child)