关于nose的各个层级(package,module,class)的fixture函数(setup 和teardown)的运行顺序与次数

本文介绍了测试用例执行过程中的不同级别设置与拆卸方法,包括包级别的setUp和tearDown、模块级别的setUpModule和tearDownModule以及类级别的setUp和tearDown。这些方法在测试执行中的调用顺序依次为包级别、模块级别和类级别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

__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方法都运行一次



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值