Skip to content

Commit

Permalink
SysCaptureBinary: decode in writeorg
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Mar 8, 2020
1 parent 56de2ac commit c4272fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/_pytest/capture.py
Expand Up @@ -687,7 +687,8 @@ def resume(self):
setattr(sys, self.name, self.tmpfile)
self._state = "resumed"

def writeorg(self, data):
def writeorg(self, data: str) -> None:
data = data.decode(self._old.encoding)
self._old.write(data)
self._old.flush()

Expand All @@ -701,6 +702,10 @@ def snap(self):
self.tmpfile.truncate()
return res

def writeorg(self, data: str) -> None:
self._old.write(data)
self._old.flush()


class TeeSysCapture(SysCapture):
def __init__(self, fd, tmpfile=None):
Expand Down
18 changes: 18 additions & 0 deletions testing/test_capture.py
Expand Up @@ -19,6 +19,7 @@
from _pytest.capture import CaptureResult
from _pytest.capture import MultiCapture
from _pytest.config import ExitCode
from _pytest.pytester import Testdir

# note: py.io capture tests where copied from
# pylib 1.4.20.dev2 (rev 13d9af95547e)
Expand Down Expand Up @@ -62,6 +63,23 @@ def test_CaptureResult() -> None:
assert str(cr) == repr_


def test_capsysbinary(testdir: Testdir) -> None:
p1 = testdir.makepyfile(
"""
def test(capsysbinary):
print("hello")
assert False, "trigger_failure"
"""
)
result = testdir.runpytest(str(p1))
result.stdout.fnmatch_lines([
'E assert False',
'*- Captured stdout call -*',
'hello',
])
assert result.ret == 1


class TestCaptureManager:
def test_getmethod_default_no_fd(self, monkeypatch):
from _pytest.capture import pytest_addoption
Expand Down

0 comments on commit c4272fd

Please sign in to comment.