Merge pull request #3315 from pytest-dev/issue/3314
Allow DontReadFromInput to produce iterator without error.
This commit is contained in:
commit
93847bfeb4
|
@ -560,7 +560,7 @@ class SysCaptureBinary(SysCapture):
|
|||
return res
|
||||
|
||||
|
||||
class DontReadFromInput(object):
|
||||
class DontReadFromInput(six.Iterator):
|
||||
"""Temporary stub class. Ideally when stdin is accessed, the
|
||||
capturing should be turned off, with possibly all data captured
|
||||
so far sent to the screen. This should be configurable, though,
|
||||
|
@ -574,7 +574,10 @@ class DontReadFromInput(object):
|
|||
raise IOError("reading from stdin while output is captured")
|
||||
readline = read
|
||||
readlines = read
|
||||
__iter__ = read
|
||||
__next__ = read
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
||||
def fileno(self):
|
||||
raise UnsupportedOperation("redirected stdin is pseudofile, "
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
During test collection, when stdin is not allowed to be read, the
|
||||
``DontReadFromStdin`` object still allow itself to be iterable and
|
||||
resolved to an iterator without crashing.
|
|
@ -751,7 +751,8 @@ def test_dontreadfrominput():
|
|||
assert not f.isatty()
|
||||
pytest.raises(IOError, f.read)
|
||||
pytest.raises(IOError, f.readlines)
|
||||
pytest.raises(IOError, iter, f)
|
||||
iter_f = iter(f)
|
||||
pytest.raises(IOError, next, iter_f)
|
||||
pytest.raises(UnsupportedOperation, f.fileno)
|
||||
f.close() # just for completeness
|
||||
|
||||
|
@ -764,7 +765,8 @@ def test_dontreadfrominput_buffer_python3():
|
|||
assert not fb.isatty()
|
||||
pytest.raises(IOError, fb.read)
|
||||
pytest.raises(IOError, fb.readlines)
|
||||
pytest.raises(IOError, iter, fb)
|
||||
iter_f = iter(f)
|
||||
pytest.raises(IOError, next, iter_f)
|
||||
pytest.raises(ValueError, fb.fileno)
|
||||
f.close() # just for completeness
|
||||
|
||||
|
|
Loading…
Reference in New Issue