From d3d8d53e413d36eb12b387c404c65e6ce18805b1 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 13 Oct 2018 16:42:33 +0200 Subject: [PATCH 1/3] tests: test_pdb: fix print statements --- testing/test_pdb.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 4739f0e2d..f04a2f3a0 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -345,7 +345,7 @@ class TestPDB(object): import pytest def test_1(): i = 0 - print ("hello17") + print("hello17") pytest.set_trace() x = 3 """ @@ -383,7 +383,7 @@ class TestPDB(object): """ import pytest def test_1(capsys): - print ("hello1") + print("hello1") pytest.set_trace() """ ) @@ -420,7 +420,7 @@ class TestPDB(object): def test_1(): pdb.set_trace() def test_2(): - print ("hello") + print("hello") assert 0 """ ) @@ -461,10 +461,10 @@ class TestPDB(object): import pytest def test_1(): i = 0 - print ("hello17") + print("hello17") pytest.set_trace() x = 3 - print ("hello18") + print("hello18") pytest.set_trace() x = 4 """ @@ -525,7 +525,7 @@ class TestPDB(object): """ def pytest_enter_pdb(config): assert config.testing_verification == 'configured' - print 'enter_pdb_hook' + print('enter_pdb_hook') def pytest_configure(config): config.testing_verification = 'configured' @@ -562,7 +562,7 @@ class TestPDB(object): custom_pdb=""" class CustomPdb(object): def set_trace(*args, **kwargs): - print 'custom set_trace>' + print('custom set_trace>') """ ) p1 = testdir.makepyfile( From 448830e6566735919068b34e5e40abccf05ff524 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 13 Oct 2018 16:33:53 +0200 Subject: [PATCH 2/3] Do not print INTERNALERROR with --pdb This gets printed by the terminal reporter already, and currently results in the same error being displayed twice, e.g. when raising an `Exception` manually from `pytest.debugging.pytest_exception_interact`. --- changelog/4132.bugfix.rst | 1 + src/_pytest/debugging.py | 3 --- testing/test_pdb.py | 6 +++++- 3 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 changelog/4132.bugfix.rst 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) From e3bf9cede4151c930092f68e7088a3e1a379241b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 13 Oct 2018 22:13:25 -0300 Subject: [PATCH 3/3] Fix linting --- testing/test_pdb.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/testing/test_pdb.py b/testing/test_pdb.py index cda553c44..6b9625b55 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -337,8 +337,16 @@ class TestPDB(object): 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 + assert ( + len( + [ + x + for x in child.before.decode().splitlines() + if x.startswith("INTERNALERROR> Traceback") + ] + ) + == 1 + ) child.sendeof() self.flush(child)