Unittest2 on python 2.6

Terry Reedy tjreedy at udel.edu
Sun Mar 18 17:58:55 EDT 2012


On 3/18/2012 4:55 PM, Andrea Crotti wrote:
> On 03/18/2012 03:46 PM, Terry Reedy wrote:
>> 1. If the difference between unittest and unittest2 is strictly a
>> matter of deletions and addition, replace unittest with the union of
>> the two.
>>
>> 2. Put the try/except dance in a compat file. Then everywhere else
>> 'from compat import unittest'. This idea is one of those used to write
>> code that will run on both 2.x and 3.x
>>
>
> 1. I think that unittest2 is a simple superset of unittest, but
> unittest2 is a backport of unittest module in Python 2.7, that's the point,
> so I don't see how I should replace it with the union.

If set A contains set B, then A is the union of the two. The danger of 
replacing unittest with unittest2 in a 2.6 installation is that 2.6 code 
that used the new features will not run in a 'normal' 2.6 installation. 
Whether that is a potential problem depends on whether you ever expect 
the code to escape from the altered environment.

I said 'union' because I was not familiar with its details. I was 
allowing for the possibility that features were both deleted and added, 
in which case the union would include all features and work with 
multiple versions. That is moot for this case but not some others.

> 2. good idea thanks

The advantage of even one explicit unittest2 import, even if hidden 
away, is that you get a proper error message if you run the code where 
unittest2 is not present.

-- 
Terry Jan Reedy




More information about the Python-list mailing list