diff options
author | Bruno Oliveira <nicoddemus@gmail.com> | 2016-10-12 17:46:47 -0300 |
---|---|---|
committer | Bruno Oliveira <nicoddemus@gmail.com> | 2016-10-12 18:19:32 -0300 |
commit | 78eec0d7f8bf177a368575271483ca575c11ad92 (patch) | |
tree | 6e83854f9842bf96034bef0428e016a972e21fc7 /_pytest/compat.py | |
parent | 3301a1c17379b6e721734bbc25040db4ff4bc956 (diff) | |
download | pytest-78eec0d7f8bf177a368575271483ca575c11ad92.tar.gz |
Handle import errors with non-ascii messages when importing plugins
Fix #1998
Diffstat (limited to '_pytest/compat.py')
-rw-r--r-- | _pytest/compat.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/_pytest/compat.py b/_pytest/compat.py index 1d8c2f331..51fc3bc5c 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -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)
\ No newline at end of file + 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) |