对于nose框架中class级别的setUp和tearDown函数的一点理解
来源:互联网 发布:淘宝联盟省钱购买 编辑:程序博客网 时间:2024/05/22 07:03
For generator methods, the setUp and tearDown methods of the class (if any) will be run before and after each generated test case. The setUp and tearDown methods do not run before the generator method itself, as this would cause setUp to run twice before the first test without an intervening tearDown.
上面这句是从nose的官方文档中摘出来的,我当时不能理解最后一句话是什么意思,就做了下面这个小实验:
class testgenerator():
def setUp(self):
print "MyTestClass setup"
def tearDown(self):
print "*******************"
def testfunc(self):
print "This is a test function"
def check_odd(self, m, mm):
print "I am the check function"
assert m % 2 == 1 or mm % 2 == 1
def test_odds(self):
for i in range(0, 3):
yield self.check_odd, i, i * 2
最后的结果如下:
MyTestClass setup
I am the check function
*******************
MyTestClass setup
I am the check function
*******************.
MyTestClass setup
I am the check function
*******************
MyTestClass setup
This is a test function
*******************.
结论: setUp and tearDown 在函数test_odds运行之前不会运行,即setUp和tearDown不修饰test_odds函数,
因为test_odds是一个generator method
PS:
运行上述例子的时候使用 nosetests -s
-s 参数使得print 的输出正常显示在屏幕上,不会被nose屏蔽掉
- 对于nose框架中class级别的setUp和tearDown函数的一点理解
- 关于nose的各个层级(package,module,class)的fixture函数(setup 和teardown)的运行顺序与次数
- python nose框架--setup/teardown
- 新版的NUnit去掉了SetUp和TearDown函数
- gtest 中Setup TearDown SetUpTestCase和TearDownTestCase 的区别
- 框架中Web容器套路,对于框架的一点理解
- Nunit C#单元测试的Setup 和Teardown 属性的使用
- JUnit测试中setup()和teardown()方法
- JUnit测试中setup()和teardown()方法
- JUnit测试中setup()和teardown()方法
- 关于python测试的nose框架和doc test以及和junit的一点对比
- 对于nose中的装饰器make_decorator的理解
- Python中单元测试框架 Nose的安装
- Python中单元测试框架Nose的安装
- 对于anchorPoint的一点理解
- 对于handler的一点理解
- 对于Session的一点理解
- 对于C++11中lambda函数的一点理解(上篇)
- Node.JS——基础知识
- C语言——字符串指针-strcpy
- L1正则和L2正则的比较分析详解
- celery初级教程(五)
- C#学习回顾笔记九:switch选择分支结构
- 对于nose框架中class级别的setUp和tearDown函数的一点理解
- PAT (Advanced) 1016. Phone Bills (25)
- linux网络编程中的字节序转换
- spring引入式整合hibernate.cfg.xml报错Invalid property 'hibernate' of bean class c3p0 ComboPooleDataSource
- HDU 5245
- Spring之AOP的两种配置方式
- Apache Beam简介
- how 2 make screen shot for app
- 快用markdown写一篇博客吧