[英]How to write a unittest with setUpClass & tearDownClass in Python 2.3
I am trying to write unittests in python 2.3. 我正在尝试在python 2.3中编写单元测试。 I've got everything working accept the class level setUp and tearDown function. 我已经完成了所有工作,接受了类级别的setUp和tearDown函数。 I've tried to look online but am not able to find a way to define these in a python 2.3 unittest case. 我试图在网上查看,但无法找到一种在python 2.3单元测试用例中定义它们的方法。
Hence, is it possible to have setUpClass() & tearDownClass() in a python 2.3 testcase? 因此,是否可以在python 2.3测试用例中使用setUpClass()和tearDownClass()? If yes, how do I go about doing that? 如果是,我该怎么做?
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. 根据Python 2.3标准库文档 ,unittest.TestCase子类应该以与该语言的最新版本相同的方式工作。
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? 如果您要完成一些更具体的事情,您能描述一下吗?
Try to use nose or other runner that is compatible with python 2.3; 尝试使用与python 2.3兼容的机鼻或其他转轮; The python 2.3 runner didn't know about this methods (setUpClass/tearDownClass). python 2.3运行程序不知道此方法(setUpClass / tearDownClass)。
In python 2.3 to decorate a function you should do manually (no syntactic sugar) like: 在python 2.3中,您需要手动完成装饰功能(无需语法糖),例如:
class MyTest(unittest.TestCase):
def setUpClass(cls): ...
setUpClass = classmethod(setUpClass)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.