Handle import errors with non-ascii messages when importing plugins

Fix #1998
This commit is contained in:
Bruno Oliveira
2016-10-12 17:46:47 -03:00
parent 3301a1c173
commit 78eec0d7f8
4 changed files with 29 additions and 6 deletions

View File

@@ -213,4 +213,18 @@ def _is_unittest_unexpected_success_a_failure():
Changed in version 3.4: Returns False if there were any
unexpectedSuccesses from tests marked with the expectedFailure() decorator.
"""
return sys.version_info >= (3, 4)
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)