[Python-Dev] unittest's redundant assertions: asserts vs. failIf/Unlesses
steve at holdenweb.com
Sun Jul 13 15:31:35 CEST 2008
Antoine Pitrou wrote:
> Ben Finney <bignose+hates-spam <at> benfinney.id.au> writes:
>> That would better be written (preferring PEP 8 names)
> Which is still a double negative ("fail" and "unless" are both negative words).
"Fail" isn't a negative. As Guido said, it's a description of the test
behavior under particular circumstances. "fail_unless_equal" says quite
clearly that the test requires equality of the values.
>> 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 which, if you care for naming consistency, is more
> important than whether or not they are implemented in terms of each other. :-)
But the important behavior is the failure of the test, not the specific
exception that is raised to fail it. Or would you prefer tests that
raise other exceptions to succeed? The exception type is an
implementation detail, and a fairly unimportant one as far as the
purpose of testing goes.
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
More information about the Python-Dev