1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
--- 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 "<CallInfo when={when!r} {status}: {value}>".format(
- when=self.when, value=value, status=status
+ when=self.when, value=safe_str(value), status=status
)
|