Unittest2 on python 2.6

Andrea Crotti andrea.crotti.0 at gmail.com
Sun Mar 18 14:31:50 CET 2012

Suppose we want to use the unittest from Python 2.7, but also want to 
support Python 2.6,
what is the best way to do it?

The solution used now is to have in setup.py

if sys.version < '2.7':

and then in every test file

     import unittest2 as unittest
except ImportError:
     import unittest

and it should work just fine, but it's a bit verbose to have this 
try/except dance everywhere..
Any ideas?

More information about the Python-list mailing list