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.

classification
Title: unittest.py, better error message
Type: enhancement Stage:
Components: Tests Versions: Python 2.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: brett.cannon, collinwinter, michael.foord, pitrou, rhettinger, stefanheimann
Priority: normal Keywords: patch

Created on 2002-07-30 22:29 by stefanheimann, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (6)
msg53607 - (view) Author: Stefan Wehr (stefanheimann) Date: 2002-07-30 22:29
These two methods of the class TestCase are not very good:

    def failUnlessEqual(self, first, second, msg=None):
        """Fail if the two objects are unequal as
determined by the '!='
           operator.
        """
        if first != second:
            raise self.failureException, \
                  (msg or '%s != %s' % (`first`, `second`))

    def failIfEqual(self, first, second, msg=None):
        """Fail if the two objects are equal as
determined by the '=='
           operator.
        """
        if first == second:
            raise self.failureException, \
                  (msg or '%s == %s' % (`first`, `second`))

The first thing is that you should print the difference
of the given values like that:

'<%s> == <%s>' % (`first`, `second`)

The < and > delimits the string and so is is easier to
detect where the string starts and where it ends.

The second thing is that I would really like to see the
two values that are (not) equal even if I provide a
message. Maybe its better to raise the exception like that:

        if msg is not None:
            msg += ' Expected: <%s>, is: <%s>' %
(first, second)
        raise self.failureException, \
                  (msg or '%s != %s' % (`first`, `second`))

bye Stefan
msg53608 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-08-18 22:19
Logged In: YES 
user_id=80475

Steve, would you like these implemented or left as is?
msg53609 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2003-05-21 04:47
Logged In: YES 
user_id=357491

I am making this an RFE since it is just a suggestion and not a bug.
msg53610 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2007-03-30 16:52
Collin, you should probably solicit Steve Purcell's input before proceeding with the one.  The request seems reasonable but the module author should have some say in the matter.
msg60123 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2008-01-18 21:22
The second proposal shouldn't be accepted as-is. If you compare two very
long or undecipherable strings, you don't want them to appear in the
failure message.
msg85748 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-04-07 21:04
This feature request was recently implemented using the 'longMessage'
class attribute on TestCase.
History
Date User Action Args
2022-04-10 16:05:32adminsetgithub: 36957
2009-04-07 21:04:40michael.foordsetstatus: open -> closed
resolution: out of date
messages: + msg85748
2009-04-07 21:00:33georg.brandlsetassignee: collinwinter -> michael.foord

nosy: + michael.foord
2008-01-18 21:22:12pitrousetnosy: + pitrou
messages: + msg60123
2008-01-06 11:59:03christian.heimessetkeywords: + patch
components: + Tests, - None
versions: + Python 2.6
2002-07-30 22:29:37stefanheimanncreate