如何使用 setUpClass 和 setUpClass 编写单元测试Python 2.3中的tearDownClass
我正在尝试用 python 2.3 编写单元测试。我已经让一切正常工作,接受类级别的设置和拆卸功能。我尝试在网上查找,但无法找到在 python 2.3 单元测试案例中定义这些的方法。
因此,是否可以有 setUpClass() & python 2.3 测试用例中的tearDownClass()?如果是,我该怎么做?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 nose 或其他与 python 2.3 兼容的运行器; python 2.3 运行程序不知道此方法(setUpClass/tearDownClass)。
在 python 2.3 中,要装饰一个函数,您应该手动执行(没有语法糖),例如:
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:
根据 Python 2.3 标准库文档,unittest.TestCase 子类化应该以与该语言的最新版本相同的方式工作。
如果您想要完成一些更具体的事情,您能描述一下吗?
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.
If there was something more specific that you're trying to accomplish, could you describe it?