What is the most pythonic way to support unittest2 features across a range of Python versions?
Question: I can think of two ways to ensure that I can use modern features from the
unittest library across a wide range of Python versions:

    
    
    try:
        from unittest2 import TestCase
    except ImportError:
        from unittest import TestCase
    

or

    
    
    import sys
    if sys.verson_info.major>=2 and sys.version_info.minor>=7:
        from unittest import TestCase
    else:
        from unittest2 import TestCase
    

Which one of these is more Pythonic?


Answer: I don't like the fact that in the second version we have to import another
module (`sys`) so my preference is for the first version:

    
    
    try:
        from unittest2 import TestCase
    except ImportError:
        from unittest import TestCase
    

EDIT:

It turns out that `pyflakes` and `flake8` are not happy with the version above
and will report a "redefinition of unused 'import' from line ... " error or
"W402 'TestCase' imported but unused" error. They seem to prefer it to be
written as follows:

    
    
    try:
        import unittest2
        TestCase = unittest2.TestCase
    except ImportError:
        import unittest
        TestCase = unittest.TestCase
    

