--- contrib/python/pytest/py2/_pytest/compat.py (index) +++ contrib/python/pytest/py2/_pytest/compat.py (working tree) @@ -378,7 +378,10 @@ if _PY3: def safe_str(v): """returns v as string""" - return str(v) + try: + return str(v) + except UnicodeEncodeError: + return str(v, encoding="utf-8") else: --- contrib/python/pytest/py2/_pytest/python.py (index) +++ contrib/python/pytest/py2/_pytest/python.py (working tree) @@ -896,7 +896,7 @@ class CallSpec2(object): @property def id(self): - return "-".join(map(str, filter(None, self._idlist))) + return "-".join(map(safe_str, filter(None, self._idlist))) def setmulti2(self, valtypes, argnames, valset, id, marks, scopenum, param_index): for arg, val in zip(argnames, valset): @@ -1218,10 +1218,10 @@ def limit_idval(limit): if len(idval) > limit: prefix = idval[:limit] # There might be same prefix for the different test cases - take item into account - name = "{}-{}".format(kw.get('item', ''), prefix) + name = "{}-{}".format(kw.get('item', ''), safe_str(prefix)) idx = names.setdefault(name, -1) + 1 names[name] = idx - idval = "{}-{}".format(prefix, idx) + idval = "{}-{}".format(safe_str(prefix), idx) return idval return wrapper --- contrib/python/pytest/py2/_pytest/runner.py (index) +++ contrib/python/pytest/py2/_pytest/runner.py (working tree) @@ -16,6 +16,7 @@ from .reports import CollectErrorRepr from .reports import CollectReport from .reports import TestReport from _pytest._code.code import ExceptionInfo +from _pytest.compat import safe_str from _pytest.outcomes import Exit from _pytest.outcomes import Skipped from _pytest.outcomes import TEST_OUTCOME @@ -241,7 +242,7 @@ class CallInfo(object): value = repr(self._result) status = "result" return "".format( - when=self.when, value=value, status=status + when=self.when, value=safe_str(value), status=status )