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

Michael Foord report at bugs.python.org
Thu Feb 16 00:29:04 CET 2012


Michael Foord <michael at voidspace.org.uk> added the comment:

assertEqual uses Python equality semantics - so if a str instance and a unicode instance compare equal then assertEqual passes. This is by design.

The type check in assertEqual, that delegates to the different comparison methods, is strict because we can't know that using the error message algorithms is sane for arbitrary subclasses - all we can know is whether an equality comparison fails or succeeds.

Using a diff algorithm for creating an error message only makes sense for text, which is why it is only done for unicode. For binary strings a diff is more likely to be unintelligible nonsense.  

For comparing unicode to strings you can call asssertMultilineEqual directly.

----------
resolution:  -> invalid
status: open -> closed

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


More information about the Python-bugs-list mailing list