Skip to content

Commit 069f32a

Browse files
committed
print captured logs before entering pdb
1 parent f263932 commit 069f32a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

_pytest/debugging.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ def _enter_pdb(node, excinfo, rep):
9797
tw.sep(">", "captured stderr")
9898
tw.line(captured_stderr)
9999

100+
captured_logs = rep.caplog
101+
if len(captured_logs) > 0:
102+
tw.sep(">", "captured logs")
103+
tw.line(captured_logs)
104+
100105
tw.sep(">", "traceback")
101106
rep.toterminal(tw)
102107
tw.sep(">", "entering PDB")

changelog/3204.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Captured logs are printed before entering pdb.

testing/test_pdb.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ def test_1():
187187
assert "captured stderr" not in output
188188
self.flush(child)
189189

190+
def test_pdb_print_captured_logs(self, testdir):
191+
p1 = testdir.makepyfile("""
192+
def test_1():
193+
import logging
194+
logging.warn("get rekt")
195+
assert False
196+
""")
197+
child = testdir.spawn_pytest("--pdb %s" % p1)
198+
child.expect("captured logs")
199+
child.expect("get rekt")
200+
child.expect("(Pdb)")
201+
child.sendeof()
202+
rest = child.read().decode("utf8")
203+
assert "1 failed" in rest
204+
self.flush(child)
205+
190206
def test_pdb_interaction_exception(self, testdir):
191207
p1 = testdir.makepyfile("""
192208
import pytest

0 commit comments

Comments
 (0)