Skip to content

Change ValueError to io.UnsupportedOperation in capture.py. Resolves … #2311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Contributors include::
Abdeali JK
Abhijeet Kasurde
Ahn Ki-Wook
Alexander Johnson
Alexei Kozlenok
Anatoly Bubenkoff
Andreas Zeidler
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
3.0.7 (unreleased)
==================

* Change capture.py's DontReadFromInput class to throw io.UnsupportedOperation errors rather
than ValueErrors in the fileno method (`#2276`).
Thanks `@metasyn` for the PR.

* Fix issue in assertion rewriting breaking due to modules silently discarding
other modules when importing fails
Expand Down Expand Up @@ -45,6 +48,7 @@
.. _@kkoukiou: https://github.com/KKoukiou
.. _@omerhadari: https://github.com/omerhadari
.. _@fbjorn: https://github.com/fbjorn
.. _@metasyn: https://github.com/metasyn

.. _#2248: https://github.com/pytest-dev/pytest/issues/2248
.. _#2137: https://github.com/pytest-dev/pytest/issues/2137
Expand All @@ -53,6 +57,7 @@
.. _#2234: https://github.com/pytest-dev/pytest/issues/2234
.. _#2238: https://github.com/pytest-dev/pytest/issues/2238
.. _#2281: https://github.com/pytest-dev/pytest/issues/2281
.. _#2276: https://github.com/pytest-dev/pytest/issues/2276

.. _PEP-479: https://www.python.org/dev/peps/pep-0479/

Expand Down
3 changes: 2 additions & 1 deletion _pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pytest

from py.io import TextIO
from io import UnsupportedOperation
unicode = py.builtin.text

patchsysdict = {0: 'stdin', 1: 'stdout', 2: 'stderr'}
Expand Down Expand Up @@ -448,7 +449,7 @@ def read(self, *args):
__iter__ = read

def fileno(self):
raise ValueError("redirected Stdin is pseudofile, has no fileno()")
raise UnsupportedOperation("redirected Stdin is pseudofile, has no fileno()")

def isatty(self):
return False
Expand Down
3 changes: 2 additions & 1 deletion testing/test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pickle
import os
import sys
from io import UnsupportedOperation

import _pytest._code
import py
Expand Down Expand Up @@ -658,7 +659,7 @@ def test_dontreadfrominput():
pytest.raises(IOError, f.read)
pytest.raises(IOError, f.readlines)
pytest.raises(IOError, iter, f)
pytest.raises(ValueError, f.fileno)
pytest.raises(UnsupportedOperation, f.fileno)
f.close() # just for completeness


Expand Down