summaryrefslogtreecommitdiff
path: root/_pytest/compat.py
diff options
context:
space:
mode:
authorBruno Oliveira <nicoddemus@gmail.com>2016-10-20 21:51:42 -0200
committerBruno Oliveira <nicoddemus@gmail.com>2016-10-20 21:51:42 -0200
commit9d00615bbf9579c110066540510be527e47467d6 (patch)
treedd3189207c954a376eb1fb1869e40244f48498ed /_pytest/compat.py
parent4667b4decc309cf5ffab95188102d459fc9ec683 (diff)
parent82fb63ca2d3c8b85d8a13038a16bd104cff1ea6e (diff)
downloadpytest-9d00615bbf9579c110066540510be527e47467d6.tar.gz
Merge remote-tracking branch 'upstream/master' into merge-master-into-features
Diffstat (limited to '_pytest/compat.py')
-rw-r--r--_pytest/compat.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/_pytest/compat.py b/_pytest/compat.py
index 16505c31c..d5fa7aa84 100644
--- a/_pytest/compat.py
+++ b/_pytest/compat.py
@@ -216,3 +216,17 @@ def _is_unittest_unexpected_success_a_failure():
unexpectedSuccesses from tests marked with the expectedFailure() decorator.
"""
return sys.version_info >= (3, 4)
+
+
+if _PY3:
+ def safe_str(v):
+ """returns v as string"""
+ return str(v)
+else:
+ def safe_str(v):
+ """returns v as string, converting to ascii if necessary"""
+ try:
+ return str(v)
+ except UnicodeError:
+ errors = 'replace'
+ return v.encode('ascii', errors)