This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gthb
Recipients ezio.melotti, gthb, michael.foord
Date 2010-05-04.13:58:48
SpamBayes Score 5.0914477e-06
Marked as misclassified No
Message-id <1272981532.18.0.496469247588.issue8313@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-05-04 13:58:53gthbsetrecipients: + gthb, ezio.melotti, michael.foord
2010-05-04 13:58:52gthbsetmessageid: <1272981532.18.0.496469247588.issue8313@psf.upfronthosting.co.za>
2010-05-04 13:58:50gthblinkissue8313 messages
2010-05-04 13:58:49gthbcreate