How to write a unittest with setUpClass & tearDownClass in Python 2.3
I am trying to write unittests in python 2.3. I've got everything working accept the class level setUp and tearDown function. I've tried to look online but am not able to find a way to define these in a python 2.3 unittest case.
Hence, is 开发者_如何转开发it possible to have setUpClass() & tearDownClass() in a python 2.3 testcase? If yes, how do I go about doing that?
Try to use nose or other runner that is compatible with python 2.3; The python 2.3 runner didn't know about this methods (setUpClass/tearDownClass).
In python 2.3 to decorate a function you should do manually (no syntactic sugar) like:
class MyTest(unittest.TestCase):
def setUpClass(cls): ...
setUpClass = classmethod(setUpClass)
According to the Python 2.3 standard library documentation, unittest.TestCase subclassing should work in the same way it works in more recent versions of the language.
import unittest
class MyTest(unittest.TestCase):
def setUp(self):
'Do stuff to set up before each test'
def tearDown(self):
'Do stuff to tear down after each test'
If there was something more specific that you're trying to accomplish, could you describe it?
精彩评论