对于nose框架中class级别的setUp和tearDown函数的一点理解
2017-09-20 23:45
381 查看
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屏蔽掉
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屏蔽掉
相关文章推荐
- 对于swiz1.0框架的一点理解
- 框架中Web容器套路,对于框架的一点理解
- python nose框架--setup/teardown
- C++:对于class来说,什么函数可以在class里面定义,什么函数最好在class外面定义(我的理解)
- 关于SpringMVC与JDBC结合实现对数据库增删改查(适合初学者理解JDBC使用,但是对于SpringMVC框架使用了扫描,不太适合初学者)
- 对于Session的一点理解
- 我对于游戏框架的理解——框架,消息机制
- 与普元技术交流后对于SCA框架的一点认识
- Android: 对于Handler的一点理解。
- android之对于view的一点深入理解
- 对于redis底层框架的理解(一)
- 对于观察者模式、Reactor模式、Proactor模式的一点理解
- day16对于缓冲池以及自定义框架的理解
- 对于数组指针的一点理解
- 对于Linux内核tty设备的一点理解
- 对于ASP.NET与J2EE框架的一点想法
- 对于索引假脱机的一点理解
- 对于项目分析的一点理解
- 对于IDEA项目路径的一点小理解
- 使用框架进行开发的一点理解