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

Andrew Bennetts andrew-pythondev at puzzling.org
Sun Jul 13 13:46:53 CEST 2008


Ben Finney wrote:
> "Guido van Rossum" <guido at python.org> writes:
[...]
> > I like using only the assertKeyword variants, removing assert_, fail*,
> > and assertEquals.
> 
> I'm the opposite. I prefer the 'fail*' variants over the 'assert*'
> variants, because "fail" tells me exactly what the function will *do*,
> while "assert" leaves it implicit what will actually happen if the
> assertion is false.
> 
> For this reason, I'd prefer the "fail*" names to be recommended, and
> the "assert*" names to be, if not deprecated, then at least
> second-class citizens.

On the other hand, “assert*” names are positive statements of what the behaviour 
of the system-under-test is.  And conversely, “fail*” names are a bit like
implementation details of how the test is written.  So I personally have a mild
preference for the assert* names.

My suspicion is that it will be very hard to get consensus on the colour of this
particular bike shed :)

-Andrew.



More information about the Python-Dev mailing list