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: the msg parameters of PyUnit assertions, such as assertEqual, should not obscure the automated diagnostics, such as '%s != %s'
Type: enhancement Stage: resolved
Components: Tests Versions: Python 3.2
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Phlip, r.david.murray
Priority: normal Keywords:

Created on 2010-01-15 18:55 by Phlip, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg97833 - (view) Author: Phlip (Phlip) Date: 2010-01-15 18:55
The various assertions are not DRY when they force you to repeat any automatic diagnostic in a message string, if you provide it.

Here's an example:

    def assertEqual(self, first, second, msg=None):
         self.assert_((first == second), msg or '%s != %s' % (first, second))

I think it should work like this:
 
     def assertEqual(self, first, second, msg=''):
         self.assert_((first == second),
 		(msg + ('\n%s != %s' % (first, second))).strip())
 
That way, if you provide a message (such as a message describing the semantic _meaning_ why "41" should not equal "42"), the assertion does not throw away the automatically generated "41 != 42".

In the current system, to correctly reflect the 41 and 42, you must add them to the msg body. This is redundant with the assertions' primary behaviors...
msg97845 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-01-15 21:05
You are looking for this:

http://docs.python.org/dev/py3k/library/unittest.html#unittest.TestCase.longMessage

I wish it were the default, but at least it exists in 2.7 and 3.x. (It can't be the default for backward compatibility reasons.)
History
Date User Action Args
2022-04-11 14:56:56adminsetgithub: 51958
2010-01-15 21:20:48brett.cannonsetstatus: open -> closed
2010-01-15 21:05:36r.david.murraysetpriority: normal

nosy: + r.david.murray
messages: + msg97845

resolution: out of date
stage: resolved
2010-01-15 18:55:17Phlipcreate