Added printing of captured stdout and stderr before entering pdb

This commit is contained in:
Brian Maissy 2018-02-12 23:17:51 +02:00
parent 8c81722a0c
commit 7656fc8320
4 changed files with 48 additions and 4 deletions

View File

@ -29,6 +29,7 @@ Benjamin Peterson
Bernard Pratz
Bob Ippolito
Brian Dorsey
Brian Maissy
Brian Okken
Brianna Laugher
Bruno Oliveira

View File

@ -85,6 +85,17 @@ def _enter_pdb(node, excinfo, rep):
# for not completely clear reasons.
tw = node.config.pluginmanager.getplugin("terminalreporter")._tw
tw.line()
captured_stdout = rep.capstdout
if len(captured_stdout) > 0:
tw.sep(">", "captured stdout")
tw.line(captured_stdout)
captured_stderr = rep.capstderr
if len(captured_stderr) > 0:
tw.sep(">", "captured stderr")
tw.line(captured_stderr)
tw.sep(">", "traceback")
rep.toterminal(tw)
tw.sep(">", "entering PDB")

1
changelog/3052.bugfix Normal file
View File

@ -0,0 +1 @@
Added printing of captured stdout/stderr before entering pdb, and improved a test which was giving false negatives about output capturing.

View File

@ -141,19 +141,50 @@ class TestPDB(object):
child.sendeof()
self.flush(child)
def test_pdb_interaction_capture(self, testdir):
def test_pdb_print_captured_stdout(self, testdir):
p1 = testdir.makepyfile("""
def test_1():
print("getrekt")
print("get\\x20rekt")
assert False
""")
child = testdir.spawn_pytest("--pdb %s" % p1)
child.expect("getrekt")
child.expect("captured stdout")
child.expect("get rekt")
child.expect("(Pdb)")
child.sendeof()
rest = child.read().decode("utf8")
assert "1 failed" in rest
assert "getrekt" not in rest
assert "get rekt" not in rest
self.flush(child)
def test_pdb_print_captured_stderr(self, testdir):
p1 = testdir.makepyfile("""
def test_1():
import sys
sys.stderr.write("get\\x20rekt")
assert False
""")
child = testdir.spawn_pytest("--pdb %s" % p1)
child.expect("captured stderr")
child.expect("get rekt")
child.expect("(Pdb)")
child.sendeof()
rest = child.read().decode("utf8")
assert "1 failed" in rest
assert "get rekt" not in rest
self.flush(child)
def test_pdb_dont_print_empty_captured_stdout_and_stderr(self, testdir):
p1 = testdir.makepyfile("""
def test_1():
assert False
""")
child = testdir.spawn_pytest("--pdb %s" % p1)
child.expect("(Pdb)")
output = child.before.decode("utf8")
child.sendeof()
assert "captured stdout" not in output
assert "captured stderr" not in output
self.flush(child)
def test_pdb_interaction_exception(self, testdir):