Gunnlaugur Thor Briem <[email protected]> added the comment:
Replacing the message with its repr seems to me at least strongly preferable to
the current “hide it all” behavior. :)
Better, msg.encode('ascii', 'backslashreplace') does what repr does with
unencodable characters, but does not add the quotes, so the behavior is only
different when it needs to be.
Better still, 'ascii' need not be hardcoded. I'm attaching a patch that sets
the encoding from an environment variable, defaulting to 'ascii', and encodes
the message with 'backslashreplace'. This makes unicode string equality
assertions much more useful for me.
The encoding could also be configurable by some clean hook for test runners to
use. unit2 could have a command-line parameter, and TextTestRunner could use
stream.encoding if not None (or PYTHONIOENCODING on Python 3).
Ideally messages should not be forced to be 8-bit strings by the failure
exception class, but I suppose that's a bigger change than you would want to
make.
The downside of using backslashreplace (or repr, for that matter) is that it
does not preserve lengths, so the diff markers can get misaligned. I find that
an acceptable tradeoff, but 'replace' is another option that preserves lengths,
at least more often.
----------
keywords: +patch
nosy: +gthb
Added file: http://bugs.python.org/file17201/unittest2-issue-8313.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue8313>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com