capture: fix FDCapture.__repr__ without targetfd_save

This commit is contained in:
Daniel Hahler 2019-03-18 02:06:52 +01:00
parent c926999cfb
commit 98981276a0
2 changed files with 12 additions and 2 deletions

View File

@ -539,7 +539,10 @@ class FDCaptureBinary(object):
self.tmpfile_fd = tmpfile.fileno()
def __repr__(self):
return "<FDCapture %s oldfd=%s>" % (self.targetfd, self.targetfd_save)
return "<FDCapture %s oldfd=%s>" % (
self.targetfd,
getattr(self, "targetfd_save", None),
)
def start(self):
""" Start capturing on targetfd using memorized tmpfile. """

View File

@ -1231,20 +1231,27 @@ class TestStdCaptureFDinvalidFD(object):
"""
import os
from _pytest import capture
def StdCaptureFD(out=True, err=True, in_=True):
return capture.MultiCapture(out, err, in_,
Capture=capture.FDCapture)
Capture=capture.FDCapture)
def test_stdout():
os.close(1)
cap = StdCaptureFD(out=True, err=False, in_=False)
assert repr(cap.out) == "<FDCapture 1 oldfd=None>"
cap.stop_capturing()
def test_stderr():
os.close(2)
cap = StdCaptureFD(out=False, err=True, in_=False)
assert repr(cap.err) == "<FDCapture 2 oldfd=None>"
cap.stop_capturing()
def test_stdin():
os.close(0)
cap = StdCaptureFD(out=False, err=False, in_=True)
assert repr(cap.in_) == "<FDCapture 0 oldfd=None>"
cap.stop_capturing()
"""
)