Unittest2 on python 2.6

Discussion in 'Python' started by Andrea Crotti, Mar 18, 2012.

  1. 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':
    tests_require.append('unittest2')

    and then in every test file

    try:
    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?
     
    Andrea Crotti, Mar 18, 2012
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cameron Laird
    Replies:
    3
    Views:
    868
    Dennis Lee Bieber
    Jun 28, 2003
  2. Irmen de Jong
    Replies:
    0
    Views:
    472
    Irmen de Jong
    Jun 30, 2003
  3. Gina Schuffenhauer

    Python 2.0 / Python 2.2

    Gina Schuffenhauer, Jul 1, 2003, in forum: Python
    Replies:
    0
    Views:
    399
    Gina Schuffenhauer
    Jul 1, 2003
  4. hab
    Replies:
    2
    Views:
    669
    Donn Cave
    Jul 7, 2003
  5. Irmen de Jong
    Replies:
    0
    Views:
    521
    Irmen de Jong
    Jul 7, 2003
  6. Replies:
    0
    Views:
    459
  7. Replies:
    0
    Views:
    937
  8. Daniel Laird

    Help with unittest2

    Daniel Laird, Dec 13, 2012, in forum: Python
    Replies:
    7
    Views:
    220
    Terry Reedy
    Dec 13, 2012
Loading...