Skip to content

Commit

Permalink
print captured logs before entering pdb
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmaissy committed Feb 18, 2018
1 parent ad7a507 commit 9d8699d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions _pytest/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ def _enter_pdb(node, excinfo, rep):
tw.sep(">", "captured stderr")
tw.line(captured_stderr)

captured_logs = rep.caplog
if len(captured_logs) > 0:
tw.sep(">", "captured logs")
tw.line(captured_logs)

tw.sep(">", "traceback")
rep.toterminal(tw)
tw.sep(">", "entering PDB")
Expand Down
1 change: 1 addition & 0 deletions changelog/3204.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Captured logs are printed before entering pdb.
16 changes: 16 additions & 0 deletions testing/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,22 @@ def test_1():
assert "captured stderr" not in output
self.flush(child)

def test_pdb_print_captured_logs(self, testdir):
p1 = testdir.makepyfile("""
def test_1():
import logging
logging.warn("get rekt")
assert False
""")
child = testdir.spawn_pytest("--pdb %s" % p1)
child.expect("captured logs")
child.expect("get rekt")
child.expect("(Pdb)")
child.sendeof()
rest = child.read().decode("utf8")
assert "1 failed" in rest
self.flush(child)

def test_pdb_interaction_exception(self, testdir):
p1 = testdir.makepyfile("""
import pytest
Expand Down

0 comments on commit 9d8699d

Please sign in to comment.