As others have mentioned, the convenience of self.assertEqual() generating a nice, useful message is a strong reason for using self.assertEqual() in my mind. However, the real deal-breaker for pure Python asserts is what happens if you use parentheses in an assert statement:
Python 2.5.1 (r251:54863, Jul 23 2008, 11:00:16) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>> assert False, "a short message" Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError: a short message
>>> assert (False, ... "a long message that needs more than 1 line") >>>
I think a short message is very pythonic. If you need to write something long you should reconsider the construct all together. Besides, it's just a string so you can write it on multiple lines with the \ backslash.
>>> assert False, ('This is ' ... 'a long message that requires me to use ' ... 'several lines to write it down.') Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError: This is a long message that requires me to use several lines to write it down.
Comment
As others have mentioned, the convenience of self.assertEqual() generating a nice, useful message is a strong reason for using self.assertEqual() in my mind. However, the real deal-breaker for pure Python asserts is what happens if you use parentheses in an assert statement:
Python 2.5.1 (r251:54863, Jul 23 2008, 11:00:16)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> assert False, "a short message"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError: a short message
>>> assert (False,
... "a long message that needs more than 1 line")
>>>
Replies
I think a short message is very pythonic. If you need to write something long you should reconsider the construct all together. Besides, it's just a string so you can write it on multiple lines with the \ backslash.
You've misplaced your parentheses:
>>> assert False, ('This is '
... 'a long message that requires me to use '
... 'several lines to write it down.')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AssertionError: This is a long message that requires me to use several lines to write it down.