Merge reset-capgture-on-reeadouterr-errors

Merge branch 'reset-capture-on-readouterr-errors' of github.com:davidszotten/pytest into merge-capmerge
This commit is contained in:
Floris Bruynooghe 2015-07-26 11:39:03 +02:00
commit e68fa641ff
2 changed files with 23 additions and 2 deletions

View File

@ -86,8 +86,10 @@ class CaptureManager:
self.deactivate_funcargs() self.deactivate_funcargs()
cap = getattr(self, "_capturing", None) cap = getattr(self, "_capturing", None)
if cap is not None: if cap is not None:
outerr = cap.readouterr() try:
cap.suspend_capturing(in_=in_) outerr = cap.readouterr()
finally:
cap.suspend_capturing(in_=in_)
return outerr return outerr
def activate_funcargs(self, pyfuncitem): def activate_funcargs(self, pyfuncitem):

View File

@ -566,6 +566,25 @@ def test_capture_binary_output(testdir):
result.assert_outcomes(passed=2) result.assert_outcomes(passed=2)
def test_error_during_readouterr(testdir):
"""Make sure we suspend capturing if errors occurr during readouterr"""
testdir.makepyfile(pytest_xyz="""
from _pytest.capture import FDCapture
def bad_snap(self):
raise Exception('boom')
assert FDCapture.snap
FDCapture.snap = bad_snap
""")
result = testdir.runpytest_subprocess(
"-p", "pytest_xyz", "--version", syspathinsert=True
)
result.stderr.fnmatch_lines([
"*in bad_snap",
" raise Exception('boom')",
"Exception: boom",
])
class TestTextIO: class TestTextIO:
def test_text(self): def test_text(self):
f = capture.TextIO() f = capture.TextIO()