Skip to content

Commit 3bfaa8a

Browse files
authored
Merge pull request #4132 from blueyed/pdb-internal-dupe
Do not print (duplicate) INTERNALERROR with --pdb.
2 parents 9fb305b + e3bf9ce commit 3bfaa8a

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

changelog/4132.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix duplicate printing of internal errors when using ``--pdb``.

src/_pytest/debugging.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ def pytest_exception_interact(self, node, call, report):
109109
_enter_pdb(node, call.excinfo, report)
110110

111111
def pytest_internalerror(self, excrepr, excinfo):
112-
for line in str(excrepr).split("\n"):
113-
sys.stderr.write("INTERNALERROR> %s\n" % line)
114-
sys.stderr.flush()
115112
tb = _postmortem_traceback(excinfo)
116113
post_mortem(tb)
117114

testing/test_pdb.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,20 @@ def pytest_runtest_protocol():
334334
)
335335
p1 = testdir.makepyfile("def test_func(): pass")
336336
child = testdir.spawn_pytest("--pdb %s" % p1)
337-
# child.expect(".*import pytest.*")
338337
child.expect("Pdb")
338+
339+
# INTERNALERROR is only displayed once via terminal reporter.
340+
assert (
341+
len(
342+
[
343+
x
344+
for x in child.before.decode().splitlines()
345+
if x.startswith("INTERNALERROR> Traceback")
346+
]
347+
)
348+
== 1
349+
)
350+
339351
child.sendeof()
340352
self.flush(child)
341353

@@ -345,7 +357,7 @@ def test_pdb_interaction_capturing_simple(self, testdir):
345357
import pytest
346358
def test_1():
347359
i = 0
348-
print ("hello17")
360+
print("hello17")
349361
pytest.set_trace()
350362
x = 3
351363
"""
@@ -383,7 +395,7 @@ def test_pdb_and_capsys(self, testdir):
383395
"""
384396
import pytest
385397
def test_1(capsys):
386-
print ("hello1")
398+
print("hello1")
387399
pytest.set_trace()
388400
"""
389401
)
@@ -420,7 +432,7 @@ def test_set_trace_capturing_afterwards(self, testdir):
420432
def test_1():
421433
pdb.set_trace()
422434
def test_2():
423-
print ("hello")
435+
print("hello")
424436
assert 0
425437
"""
426438
)
@@ -461,10 +473,10 @@ def test_pdb_interaction_capturing_twice(self, testdir):
461473
import pytest
462474
def test_1():
463475
i = 0
464-
print ("hello17")
476+
print("hello17")
465477
pytest.set_trace()
466478
x = 3
467-
print ("hello18")
479+
print("hello18")
468480
pytest.set_trace()
469481
x = 4
470482
"""
@@ -525,7 +537,7 @@ def test_enter_pdb_hook_is_called(self, testdir):
525537
"""
526538
def pytest_enter_pdb(config):
527539
assert config.testing_verification == 'configured'
528-
print 'enter_pdb_hook'
540+
print('enter_pdb_hook')
529541
530542
def pytest_configure(config):
531543
config.testing_verification = 'configured'
@@ -562,7 +574,7 @@ def test_pdb_custom_cls_with_settrace(self, testdir, monkeypatch):
562574
custom_pdb="""
563575
class CustomPdb(object):
564576
def set_trace(*args, **kwargs):
565-
print 'custom set_trace>'
577+
print('custom set_trace>')
566578
"""
567579
)
568580
p1 = testdir.makepyfile(

0 commit comments

Comments
 (0)