__init__.py中的代码:
def setUp():
print "This is a package setup function"
def tearDown():
print "This is a package teardown function"
module test.py中的代码:
def setUpModule():
print "This is a module function"
def tearDownModule():
print "This is a module function"
class testfixture():
def setUp(self):
print "This is a class setup function"
def tearDown(self):
print "This is a class teardown function"
def testfunc(self):
print "++++++++++++++"
运行的结果:
This is a package setup function
This is a module function
This is a class setup function
++++++++++++++
This is a class teardown function
This is a module function
package 级别的setup和teardown函数在__init__.py文件中,只运行一次,而且是排在module的前面
module级别的setup和tearwown函数在test.py文件中,只运行一次,排在class的前面
class级别的setup和teardown函数在test.py文件中,而且是在class的内部,并且是每一个test方法都运行一次