[Python-Dev] unittest missing assertNotRaises

Terry Reedy tjreedy at udel.edu
Tue Sep 27 22:06:22 CEST 2011


On 9/27/2011 2:46 PM, Wilfred Hughes wrote:
> Hi folks
>
> I wasn't sure if this warranted a bug in the tracker, so I thought I'd
> raise it here first.
>
> unittest has assertIn, assertNotIn, assertEqual, assertNotEqual and so

These all test possible specification conditions and sensible test 
conditions. For instance -1 and particularly 3 should not be in 
range(3). Including 3 is a realistic possible error. If you partition a 
set into subsets < x and > x, x should not be in either, but an easy 
mistake would put it in either or both.

> Is there any particular motivation for not putting it in?

You have 'motivation' backwards. There are an infinity of things we 
could add. We need a positive, substantial reason with real use cases to 
add something.

An expression should return a particular value or return a particular 
expression. If it returns a value, testing that it is the correct value 
eliminates all exceptions. And testing for an expected exception 
eliminates all others. If there is an occasional needed for the 
proposal, one can write the same code you did, but with the possibility 
of excluding more than one exception. So I do not see any need for the 
proposal.

-- 
Terry Jan Reedy



More information about the Python-Dev mailing list