新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
創(chuàng)新互聯(lián)Python教程:python setup和teardown的使用
說(shuō)明

1、setup/teardown:每種方法將執(zhí)行一次,無(wú)論是類(lèi)內(nèi)還是類(lèi)外。
2、Setup:方法運(yùn)行前執(zhí)行,表示前置條件。
必須在每個(gè)用例執(zhí)行前執(zhí)行一次。
3、Teardown:方法運(yùn)行后才能執(zhí)行,表示資源釋放。
每次用例執(zhí)行后都會(huì)執(zhí)行一次。
實(shí)例
# file_name: test_setup.py
import pytest
def setup():
print("...類(lèi)外setup...")
def test_create():
print("類(lèi)外test_create")
def test_view():
print("類(lèi)外test_view")
class TestSetupClass:
def setup(self):
print("...類(lèi)內(nèi)setup...")
def test_create(self):
print("類(lèi)內(nèi)test_create")
def test_view(self):
print("類(lèi)內(nèi)test_view")
def teardown(self):
print("...類(lèi)內(nèi)teardown...")
def teardown():
print("...類(lèi)外teardown...")
if __name__ == '__main__':
pytest.main(['-vs', 'test_setup.py'])以上就是python setup和teardown的使用,希望對(duì)大家有所幫助。更多Python學(xué)習(xí)指路:創(chuàng)新互聯(lián)python教程
本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。
分享文章:創(chuàng)新互聯(lián)Python教程:python setup和teardown的使用
網(wǎng)站URL:http://m.5511xx.com/article/djjdspo.html


咨詢(xún)
建站咨詢(xún)
