Skip to content

Commit 65dbc4d

Browse files
committed
print captured logs before entering pdb
1 parent 063e2da commit 65dbc4d

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

_pytest/debugging.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ def _enter_pdb(node, excinfo, rep):
8585
# for not completely clear reasons.
8686
tw = node.config.pluginmanager.getplugin("terminalreporter")._tw
8787
tw.line()
88+
89+
captured_logs = rep.caplog
90+
if len(captured_logs) > 0:
91+
tw.sep(">", "captured logs")
92+
tw.line(captured_logs)
93+
8894
tw.sep(">", "traceback")
8995
rep.toterminal(tw)
9096
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
@@ -156,6 +156,22 @@ def test_1():
156156
assert "getrekt" not in rest
157157
self.flush(child)
158158

159+
def test_pdb_print_captured_logs(self, testdir):
160+
p1 = testdir.makepyfile("""
161+
def test_1():
162+
import logging
163+
logging.warn("get rekt")
164+
assert False
165+
""")
166+
child = testdir.spawn_pytest("--pdb %s" % p1)
167+
child.expect("captured logs")
168+
child.expect("get rekt")
169+
child.expect("(Pdb)")
170+
child.sendeof()
171+
rest = child.read().decode("utf8")
172+
assert "1 failed" in rest
173+
self.flush(child)
174+
159175
def test_pdb_interaction_exception(self, testdir):
160176
p1 = testdir.makepyfile("""
161177
import pytest

0 commit comments

Comments
 (0)