diff options
author | Anthony Sottile <asottile@umich.edu> | 2017-02-19 09:16:32 -0800 |
---|---|---|
committer | Anthony Sottile <asottile@umich.edu> | 2017-02-23 17:46:27 -0800 |
commit | 6ba3475448d3ab78b4bf7de9aa81baa47357a70d (patch) | |
tree | d7f30c67255895ef4c42c9729af48302d48216bc /_pytest/compat.py | |
parent | 44ad369c17b2e878875cfa809a4908462aac1b1d (diff) | |
download | pytest-6ba3475448d3ab78b4bf7de9aa81baa47357a70d.tar.gz |
Make capsys more like stdio streams in python3. Resolves #1407.
Diffstat (limited to '_pytest/compat.py')
-rw-r--r-- | _pytest/compat.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/_pytest/compat.py b/_pytest/compat.py index e097dee51..09df385d1 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -251,3 +251,19 @@ else: except UnicodeError: errors = 'replace' return v.encode('ascii', errors) + + +if _PY2: + from py.io import TextIO as CaptureIO +else: + import io + + class CaptureIO(io.TextIOWrapper): + def __init__(self): + super(CaptureIO, self).__init__( + io.BytesIO(), + encoding='UTF-8', newline='', write_through=True, + ) + + def getvalue(self): + return self.buffer.getvalue().decode('UTF-8') |