diff --git a/_pytest/compat.py b/_pytest/compat.py index 45f9f86d4..edb68c075 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -121,7 +121,6 @@ if sys.version_info[:2] == (2, 6): if _PY3: - import codecs imap = map izip = zip STRING_TYPES = bytes, str @@ -146,13 +145,7 @@ if _PY3: """ if isinstance(val, bytes): - if val: - # source: http://goo.gl/bGsnwC - encoded_bytes, _ = codecs.escape_encode(val) - return encoded_bytes.decode('ascii') - else: - # empty bytes crashes codecs.escape_encode (#1087) - return '' + return val.decode('ascii', 'backslashreplace') else: return val.encode('unicode_escape').decode('ascii') else: diff --git a/changelog/2734.trivial b/changelog/2734.trivial new file mode 100644 index 000000000..bbf701d16 --- /dev/null +++ b/changelog/2734.trivial @@ -0,0 +1 @@ +- simplify ascii string escaping by using the backslashreplace error handler \ No newline at end of file