Reputation: 51
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?
Upvotes: 5
Views: 1102
Reputation: 8751
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'
Upvotes: 8