diff --git a/src/tox/_pytestplugin.py b/src/tox/_pytestplugin.py index 14d166bd6..7637880ff 100644 --- a/src/tox/_pytestplugin.py +++ b/src/tox/_pytestplugin.py @@ -176,9 +176,13 @@ def outlines(self): 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 873731b02..dcb6e3a06 100644 --- a/tests/unit/test_pytest_plugins.py +++ b/tests/unit/test_pytest_plugins.py @@ -4,11 +4,12 @@ """ 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 @@ def test_on_py_path(self): ) 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)