[issue14025] unittest.TestCase.assertEqual does not show diff when comparing str with unicode

Jaap Karssenberg report at bugs.python.org
Fri Feb 17 09:37:18 CET 2012


Jaap Karssenberg <jaap.karssenberg at gmail.com> added the comment:

On Fri, Feb 17, 2012 at 1:23 AM, Ezio Melotti <report at bugs.python.org>wrote:

>
> Ezio Melotti <ezio.melotti at gmail.com> added the comment:
>
> If you really want the diff you could use assertMultiLineEqual, but even
> on Python 2 you shouldn't mix str and unicode.  I would rather fix the code
> to return unicode than using assertMultilineEqual to get a diff between str
> and unicode.  Moreover assertMultiLineEqual only works if the str happens
> to be ASCII-only:
>

Yes I'm aware of that. However to my mind there is an inconsistency between
having assertEqual dispatch per type and having to use explicitly
assertMultiLineEqual. If assertMultiLineEqual accepts basestring, I should
be able to register it as such.

More practically I have a large suite of code using assertEqual comparing
mixed str and unicode. This code was written before the diff function was
available (in fact I had a custom diff function in the subclass). As long
as tests are OK this works fine, so I rather not touch them, but if they
fail I don't get the output I need.

Anyway, since I feel there is no consensus on this, I went ahead and
patched assertEqual in my custom subclass and move ahead. I can submit a
formal patch if there is a chance of it being accepted.

Regards,

Jaap

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14025>
_______________________________________


More information about the Python-bugs-list mailing list