File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ Javier Domingo Cansino
6969Javier Romero
7070John Towler
7171Jon Sonesen
72+ Jordan Guymon
7273Joshua Bronson
7374Jurko Gospodnetić
7475Justyna Janczyszyn
Original file line number Diff line number Diff line change 66* Improve error message when passing non-string ids to ``pytest.mark.parametrize `` (`#1857 `_).
77 Thanks `@okken `_ for the report and `@nicoddemus `_ for the PR.
88
9- *
9+ * Add ``buffer `` attribute to stdin stub class ``pytest.capture.DontReadFromInput ``
10+ Thanks `@joguSD `_ for the PR.
1011
1112*
1213
14+ .. _@joguSD : https://github.com/joguSD
1315
1416.. _#1857 : https://github.com/pytest-dev/pytest/issues/1857
1517
Original file line number Diff line number Diff line change @@ -455,6 +455,13 @@ def isatty(self):
455455 def close (self ):
456456 pass
457457
458+ @property
459+ def buffer (self ):
460+ if sys .version_info >= (3 ,0 ):
461+ return self
462+ else :
463+ raise AttributeError ('redirected stdin has no attribute buffer' )
464+
458465
459466def _readline_workaround ():
460467 """
Original file line number Diff line number Diff line change @@ -662,6 +662,28 @@ def test_dontreadfrominput():
662662 f .close () # just for completeness
663663
664664
665+ @pytest .mark .skipif ('sys.version_info < (3,)' , reason = 'python2 has no buffer' )
666+ def test_dontreadfrominput_buffer_python3 ():
667+ from _pytest .capture import DontReadFromInput
668+ f = DontReadFromInput ()
669+ fb = f .buffer
670+ assert not fb .isatty ()
671+ pytest .raises (IOError , fb .read )
672+ pytest .raises (IOError , fb .readlines )
673+ pytest .raises (IOError , iter , fb )
674+ pytest .raises (ValueError , fb .fileno )
675+ f .close () # just for completeness
676+
677+
678+ @pytest .mark .skipif ('sys.version_info >= (3,)' , reason = 'python2 has no buffer' )
679+ def test_dontreadfrominput_buffer_python2 ():
680+ from _pytest .capture import DontReadFromInput
681+ f = DontReadFromInput ()
682+ with pytest .raises (AttributeError ):
683+ f .buffer
684+ f .close () # just for completeness
685+
686+
665687@pytest .yield_fixture
666688def tmpfile (testdir ):
667689 f = testdir .makepyfile ("" ).open ('wb+' )
You can’t perform that action at this time.
0 commit comments