Skip to content

Commit c8f7e50

Browse files
authored
Merge pull request #5262 from asottile/mode_non_binary
Remove 'b' from sys.stdout.mode
2 parents 494ac28 + 4318698 commit c8f7e50

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

changelog/5257.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure that ``sys.stdout.mode`` does not include ``'b'`` as it is a text stream.

src/_pytest/capture.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ def name(self):
447447
"""Ensure that file.name is a string."""
448448
return repr(self.buffer)
449449

450+
@property
451+
def mode(self):
452+
return self.buffer.mode.replace("b", "")
453+
450454
def __getattr__(self, name):
451455
return getattr(object.__getattribute__(self, "buffer"), name)
452456

testing/test_capture.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,9 @@ def test_simple_resume_suspend(self, tmpfile):
10511051
cap.done()
10521052
pytest.raises(AttributeError, cap.suspend)
10531053

1054+
def test_capfd_sys_stdout_mode(self, capfd):
1055+
assert "b" not in sys.stdout.mode
1056+
10541057

10551058
@contextlib.contextmanager
10561059
def saved_fd(fd):

0 commit comments

Comments
 (0)