Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/5256.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle internal error due to a lone surrogate unicode character not being representable in Jython.
10 changes: 9 additions & 1 deletion src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,15 @@ def _get_line_with_reprcrash_message(config, rep, termwidth):
# u'😄' will result in a High Surrogate (U+D83D) character, which is
# rendered as u'�'; in this case we just strip that character out as it
# serves no purpose being rendered
msg = msg.rstrip(u"\uD83D")
try:
surrogate = six.unichr(0xD83D)
msg = msg.rstrip(surrogate)
except ValueError: # pragma: no cover
# Jython cannot represent this lone surrogate at all (#5256):
# ValueError: unichr() arg is a lone surrogate in range
# (0xD800, 0xDFFF) (Jython UTF-16 encoding)
# ignore this case as it shouldn't appear in the string anyway
pass
msg += ellipsis
line += sep + msg
return line
Expand Down