diff options
author | Anthony Sottile <asottile@umich.edu> | 2019-04-16 07:34:49 -0700 |
---|---|---|
committer | Bernát Gábor <gaborjbernat@gmail.com> | 2019-04-16 15:34:49 +0100 |
commit | 4c3a891a40642854dac0b97947df47a21391b0c7 (patch) | |
tree | b349b6ffa68c357662552723da1da6dcabc51dc6 | |
parent | 5cf41e7f2f945bb3ba679e0e72e395a957cc0b78 (diff) | |
download | tox-git-4c3a891a40642854dac0b97947df47a21391b0c7.tar.gz |
Fix RunResult unicode repr errors (#1264)
-rw-r--r-- | src/tox/_pytestplugin.py | 8 | ||||
-rw-r--r-- | tests/unit/test_pytest_plugins.py | 15 |
2 files changed, 20 insertions, 3 deletions
diff --git a/src/tox/_pytestplugin.py b/src/tox/_pytestplugin.py index 14d166bd..7637880f 100644 --- a/src/tox/_pytestplugin.py +++ b/src/tox/_pytestplugin.py @@ -176,9 +176,13 @@ class RunResult: return err + out def __repr__(self): - return "RunResult(ret={}, args={}, out=\n{}\n, err=\n{})".format( - self.ret, " ".join(str(i) for i in self.args), self.out, self.err + res = "RunResult(ret={}, args={!r}, out=\n{}\n, err=\n{})".format( + self.ret, self.args, self.out, self.err ) + if six.PY2: + return res.encode("UTF-8") + else: + return res def output(self): return "{}\n{}\n{}".format(self.ret, self.err, self.out) diff --git a/tests/unit/test_pytest_plugins.py b/tests/unit/test_pytest_plugins.py index 873731b0..dcb6e3a0 100644 --- a/tests/unit/test_pytest_plugins.py +++ b/tests/unit/test_pytest_plugins.py @@ -4,11 +4,12 @@ project test suite, e.g. as shown by the code coverage report. """ import os +import sys import py.path import pytest -from tox._pytestplugin import _filedefs_contains, _path_parts +from tox._pytestplugin import RunResult, _filedefs_contains, _path_parts class TestInitProj: @@ -111,3 +112,15 @@ class TestPathParts: ) def test_filedefs_contains(base, filedefs, target, expected): assert bool(_filedefs_contains(base, filedefs, target)) == expected + + +def test_run_result_repr(capfd): + with RunResult(["hello", "world"], capfd) as run_result: + # simulate tox writing some unicode output + stdout_buffer = getattr(sys.stdout, "buffer", sys.stdout) + stdout_buffer.write(u"\u2603".encode("UTF-8")) + + # must not `UnicodeError` on repr(...) + ret = repr(run_result) + # must be native `str`, (bytes in py2, str in py3) + assert isinstance(ret, str) |