File tree Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Expand file tree Collapse file tree 3 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -560,7 +560,7 @@ def snap(self):
560
560
return res
561
561
562
562
563
- class DontReadFromInput (object ):
563
+ class DontReadFromInput (six . Iterator ):
564
564
"""Temporary stub class. Ideally when stdin is accessed, the
565
565
capturing should be turned off, with possibly all data captured
566
566
so far sent to the screen. This should be configurable, though,
@@ -574,7 +574,10 @@ def read(self, *args):
574
574
raise IOError ("reading from stdin while output is captured" )
575
575
readline = read
576
576
readlines = read
577
- __iter__ = read
577
+ __next__ = read
578
+
579
+ def __iter__ (self ):
580
+ return self
578
581
579
582
def fileno (self ):
580
583
raise UnsupportedOperation ("redirected stdin is pseudofile, "
Original file line number Diff line number Diff line change
1
+ During test collection, when stdin is not allowed to be read, the
2
+ ``DontReadFromStdin `` object still allow itself to be iterable and
3
+ resolved to an iterator without crashing.
Original file line number Diff line number Diff line change @@ -751,7 +751,8 @@ def test_dontreadfrominput():
751
751
assert not f .isatty ()
752
752
pytest .raises (IOError , f .read )
753
753
pytest .raises (IOError , f .readlines )
754
- pytest .raises (IOError , iter , f )
754
+ iter_f = iter (f )
755
+ pytest .raises (IOError , next , iter_f )
755
756
pytest .raises (UnsupportedOperation , f .fileno )
756
757
f .close () # just for completeness
757
758
@@ -764,7 +765,8 @@ def test_dontreadfrominput_buffer_python3():
764
765
assert not fb .isatty ()
765
766
pytest .raises (IOError , fb .read )
766
767
pytest .raises (IOError , fb .readlines )
767
- pytest .raises (IOError , iter , fb )
768
+ iter_f = iter (f )
769
+ pytest .raises (IOError , next , iter_f )
768
770
pytest .raises (ValueError , fb .fileno )
769
771
f .close () # just for completeness
770
772
You can’t perform that action at this time.
0 commit comments