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

Ben Finney bignose+hates-spam at benfinney.id.au
Sun Jul 13 15:34:51 CEST 2008

Antoine Pitrou <solipsis at pitrou.net> writes:

> Ben Finney <bignose+hates-spam <at> benfinney.id.au> writes:
> > That would better be written (preferring PEP 8 names)
> > "fail_unless_equal".
> Which is still a double negative ("fail" and "unless" are both
> negative words).

Hmm, not to this native-English-speaker's ear. "fail" is a verb
stating what will be done, while "unless" and "if" are the conditions
under which it will be done.

> > That's another reason to avoid "assert" in the name: these methods
> > *don't* necessarily use the 'assert' statement.
> But all those constructs (assert, assertEqual, etc.) raise the same
> exception type named AssertionError

Only by default. They can be overridden to raise any exception type.

The only thing they have in common at that point (when the exception
is raised) is that they have failed the test.

 \       “First things first, but not necessarily in that order.” —The |
  `\                                              Doctor, _Doctor Who_ |
_o__)                                                                  |
Ben Finney

More information about the Python-Dev mailing list