capture: fix FDCapture.__repr__ without targetfd_save
This commit is contained in:
parent
c926999cfb
commit
98981276a0
|
@ -539,7 +539,10 @@ class FDCaptureBinary(object):
|
||||||
self.tmpfile_fd = tmpfile.fileno()
|
self.tmpfile_fd = tmpfile.fileno()
|
||||||
|
|
||||||
def __repr__(self):
|
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):
|
def start(self):
|
||||||
""" Start capturing on targetfd using memorized tmpfile. """
|
""" Start capturing on targetfd using memorized tmpfile. """
|
||||||
|
|
|
@ -1231,20 +1231,27 @@ class TestStdCaptureFDinvalidFD(object):
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
from _pytest import capture
|
from _pytest import capture
|
||||||
|
|
||||||
def StdCaptureFD(out=True, err=True, in_=True):
|
def StdCaptureFD(out=True, err=True, in_=True):
|
||||||
return capture.MultiCapture(out, err, in_,
|
return capture.MultiCapture(out, err, in_,
|
||||||
Capture=capture.FDCapture)
|
Capture=capture.FDCapture)
|
||||||
|
|
||||||
def test_stdout():
|
def test_stdout():
|
||||||
os.close(1)
|
os.close(1)
|
||||||
cap = StdCaptureFD(out=True, err=False, in_=False)
|
cap = StdCaptureFD(out=True, err=False, in_=False)
|
||||||
|
assert repr(cap.out) == "<FDCapture 1 oldfd=None>"
|
||||||
cap.stop_capturing()
|
cap.stop_capturing()
|
||||||
|
|
||||||
def test_stderr():
|
def test_stderr():
|
||||||
os.close(2)
|
os.close(2)
|
||||||
cap = StdCaptureFD(out=False, err=True, in_=False)
|
cap = StdCaptureFD(out=False, err=True, in_=False)
|
||||||
|
assert repr(cap.err) == "<FDCapture 2 oldfd=None>"
|
||||||
cap.stop_capturing()
|
cap.stop_capturing()
|
||||||
|
|
||||||
def test_stdin():
|
def test_stdin():
|
||||||
os.close(0)
|
os.close(0)
|
||||||
cap = StdCaptureFD(out=False, err=False, in_=True)
|
cap = StdCaptureFD(out=False, err=False, in_=True)
|
||||||
|
assert repr(cap.in_) == "<FDCapture 0 oldfd=None>"
|
||||||
cap.stop_capturing()
|
cap.stop_capturing()
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue