[Python-Dev] Unittest PEP do's and don'ts (BDFL pronouncement)

Andrew Bennetts andrew-pythondev at puzzling.org
Thu Jul 17 03:07:30 CEST 2008

Ben Finney wrote:
> Andrew Bennetts <andrew-pythondev at puzzling.org> writes:
> > This one is easily solved by making assertRaises return the
> > exception it caught.
> That breaks one simple feature of the unittest API: that all the test
> methods will either raise a failure asertion, or return None.

How is returning None a feature?  I've never seen code that somehow depends on
assertRaises returning None.  This “feature” is not documented as being
significant in the unittest module documentation anywhere.  It is not mentioned
anywhere in the *eight* pages of the xUnit Test Patterns book[1] dedicated to
Assertion Methods in their general form.  Where did you get the notion that it
is a feature?

Further, I have lots of evidence that in practice returning the exception
instance from assertRaises is not a problem, and is in fact quite useful.

I'd quote “Practicality beats purity”, but I'm not even sure if it is purity
that you have in mind.  Demanding that assertion methods return None seems like
foolish consistency and dogma.


[1] _xUnit Test Patterns: Refactoring Test Code_, by Gerard Meszaros.

More information about the Python-Dev mailing list