From 4318698baeab38a413d8c3684248f95a2fed3979 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 14 May 2019 14:54:03 -0700 Subject: [PATCH] Remove 'b' from sys.stdout.mode --- changelog/5257.bugfix.rst | 1 + src/_pytest/capture.py | 4 ++++ testing/test_capture.py | 3 +++ 3 files changed, 8 insertions(+) create mode 100644 changelog/5257.bugfix.rst diff --git a/changelog/5257.bugfix.rst b/changelog/5257.bugfix.rst new file mode 100644 index 000000000..520519088 --- /dev/null +++ b/changelog/5257.bugfix.rst @@ -0,0 +1 @@ +Ensure that ``sys.stdout.mode`` does not include ``'b'`` as it is a text stream. diff --git a/src/_pytest/capture.py b/src/_pytest/capture.py index 25eab7fdf..560171134 100644 --- a/src/_pytest/capture.py +++ b/src/_pytest/capture.py @@ -447,6 +447,10 @@ class EncodedFile(object): """Ensure that file.name is a string.""" return repr(self.buffer) + @property + def mode(self): + return self.buffer.mode.replace("b", "") + def __getattr__(self, name): return getattr(object.__getattribute__(self, "buffer"), name) diff --git a/testing/test_capture.py b/testing/test_capture.py index 5d80eb63d..f1802cc16 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -1051,6 +1051,9 @@ class TestFDCapture(object): cap.done() pytest.raises(AttributeError, cap.suspend) + def test_capfd_sys_stdout_mode(self, capfd): + assert "b" not in sys.stdout.mode + @contextlib.contextmanager def saved_fd(fd):