Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unittest setUpClass alternative for python < 2.7

In Python 2.7, it is possible to run class level setup in unittest.Testcase as follows:

class ClassName(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        print 'Some class level setup'

Unfortunately, I need to run some tests in Python 2.6 environment. What is the alternative for setUpClass in that version?

like image 722
user3130142 Avatar asked Dec 23 '13 16:12

user3130142


1 Answers

The Python 2.7 version of unittest is available for Python 2.6 (actually, all the way back to Python 2.3!) as the unittest2 module on PyPI: https://pypi.python.org/pypi/unittest2

Once that's installed, setupClass methods will work on your test classes:

import unittest2
class ClassName(unittest2.TestCase):
    @classmethod
    def setUpClass(cls):
        print 'Some class level setup'
like image 55
babbageclunk Avatar answered Nov 03 '22 08:11

babbageclunk