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?
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With