[Python-Dev] unittest's redundant assertions: asserts vs. failIf/Unlesses
solipsis at pitrou.net
Sun Jul 13 16:39:48 CEST 2008
Let's split hairs a little...
Steve Holden <steve <at> holdenweb.com> writes:
> "Fail" isn't a negative. As Guido said, it's a description of the test
> behavior under particular circumstances.
In most circumstances, "fail" is a negative word defined as the contrary of
something else (that is, as the "failure to pass/succeed/perform/achieve/..."),
while the reverse is not true (few people would define "success" or "passing a
test" as the negative of "failure", except in desperate circumstances). Although
I'm not a native English speaker, I don't think our respective languages and
cultures differ on this point.
> "fail_unless_equal" says quite
> clearly that the test requires equality of the values.
Actually, saying "that the test requires equality of the values" translates
directly into an "assert equals" (or "enforce equals" if you want a stronger
word) rather than a "fail if not equal". It is a grammatical fact...
In other words, if you express a requirement, you intent to say how the
implementation under test is supposed to behave for it to be considered
successful, not the conditions under which its behaviour constitutes a failure.
As you said, if an exception is thrown which isn't part of the testing protocol
(e.g. something other than an AssertionError), the test is still said to fail...
if the intent of testing were to test for failure conditions, on the contrary,
the test would be said to be passed (because it wouldn't have met the failure
More information about the Python-Dev