Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to skip a unittest case in python 2.6

unittest.skip* decorators and methods as below (see here for more details) were added since python2.7 and i found they are quite useful.

unittest.skip(reason)
unittest.skipIf(condition, reason)
unittest.skipUnless(condition, reason)

However, my question is how we should do the similar if working with python2.6?

like image 622
zhutoulala Avatar asked Dec 05 '13 08:12

zhutoulala


1 Answers

If you can't use unittest2 and don't mind having a different number of tests in Python 2.6, you can write simple decorators that make the tests disappear:

try:
    from unittest import skip, skipUnless
except ImportError:
    def skip(f):
        return lambda self: None

    def skipUnless(condition, reason):
        if condition:
            return lambda x: x
        else:
            return lambda x: None
like image 95
Thomas Avatar answered Oct 12 '22 23:10

Thomas