Added printing of captured stdout and stderr before entering pdb
This commit is contained in:
parent
8c81722a0c
commit
7656fc8320
1
AUTHORS
1
AUTHORS
|
@ -29,6 +29,7 @@ Benjamin Peterson
|
||||||
Bernard Pratz
|
Bernard Pratz
|
||||||
Bob Ippolito
|
Bob Ippolito
|
||||||
Brian Dorsey
|
Brian Dorsey
|
||||||
|
Brian Maissy
|
||||||
Brian Okken
|
Brian Okken
|
||||||
Brianna Laugher
|
Brianna Laugher
|
||||||
Bruno Oliveira
|
Bruno Oliveira
|
||||||
|
|
|
@ -85,6 +85,17 @@ def _enter_pdb(node, excinfo, rep):
|
||||||
# for not completely clear reasons.
|
# for not completely clear reasons.
|
||||||
tw = node.config.pluginmanager.getplugin("terminalreporter")._tw
|
tw = node.config.pluginmanager.getplugin("terminalreporter")._tw
|
||||||
tw.line()
|
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")
|
tw.sep(">", "traceback")
|
||||||
rep.toterminal(tw)
|
rep.toterminal(tw)
|
||||||
tw.sep(">", "entering PDB")
|
tw.sep(">", "entering PDB")
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Added printing of captured stdout/stderr before entering pdb, and improved a test which was giving false negatives about output capturing.
|
|
@ -141,13 +141,14 @@ class TestPDB(object):
|
||||||
child.sendeof()
|
child.sendeof()
|
||||||
self.flush(child)
|
self.flush(child)
|
||||||
|
|
||||||
def test_pdb_interaction_capture(self, testdir):
|
def test_pdb_print_captured_stdout(self, testdir):
|
||||||
p1 = testdir.makepyfile("""
|
p1 = testdir.makepyfile("""
|
||||||
def test_1():
|
def test_1():
|
||||||
print("getrekt")
|
print("get\\x20rekt")
|
||||||
assert False
|
assert False
|
||||||
""")
|
""")
|
||||||
child = testdir.spawn_pytest("--pdb %s" % p1)
|
child = testdir.spawn_pytest("--pdb %s" % p1)
|
||||||
|
child.expect("captured stdout")
|
||||||
child.expect("get rekt")
|
child.expect("get rekt")
|
||||||
child.expect("(Pdb)")
|
child.expect("(Pdb)")
|
||||||
child.sendeof()
|
child.sendeof()
|
||||||
|
@ -156,6 +157,36 @@ class TestPDB(object):
|
||||||
assert "get rekt" not in rest
|
assert "get rekt" not in rest
|
||||||
self.flush(child)
|
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):
|
def test_pdb_interaction_exception(self, testdir):
|
||||||
p1 = testdir.makepyfile("""
|
p1 = testdir.makepyfile("""
|
||||||
import pytest
|
import pytest
|
||||||
|
|
Loading…
Reference in New Issue