[Python-Dev] unittest's redundant assertions: asserts vs. failIf/Unlesses

Michael Foord fuzzyman at voidspace.org.uk
Sun Jul 13 16:45:58 CEST 2008


Antoine Pitrou wrote:
> 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. 
>   

Agreed. I tend to think of testing as action followed by assertion - I 
do this and this should have happened. Your tests usually define 
'expected behaviour' rather than defining how your code won't fail...

Michael

> 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
> conditions).
>
> Regards
>
> Antoine.
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
>   


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/
http://www.trypython.org/
http://www.ironpython.info/
http://www.theotherdelia.co.uk/
http://www.resolverhacks.net/



More information about the Python-Dev mailing list