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

Steven D'Aprano steve at pearwood.info
Sun Jul 13 18:20:52 CEST 2008

On Mon, 14 Jul 2008 12:39:48 am 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).

"Few people"? Do you have studies to support your claim, or are you just 
projecting your own opinion as if it were an objective fact?

I often consider "success" as the negative of failure: my code didn't 
fail. The bridge didn't fall down. The invasion didn't get bogged down 
in a long and pointless guerrilla war. The medicine didn't have massive 
side-effects. These are all successes.



Speaking for myself, the last three are far more natural to me.

I'll also point out that in science, success is often considered the 
opposite of failure. You design your experiments to disprove the 
theory, to fail, and if they don't fail, the theory is considered 
successful. A theory is considered "correct" when it has failed to 
fail. Some philosophers of science, like the late Karl Popper, consider 
this falsification to be the defining characteristic of science.


> 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.

Please don't tell me what my intent is. Unless you are a mind-reader, 
you have no way of telling what my intent is.

When I write tests, my intent is often to specify the conditions that 
constitute a failure. I don't want to negate it to specify a success 
just to satisfy you.


More information about the Python-Dev mailing list