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

1、setup/teardown:每種方法將執(zhí)行一次,無論是類內(nè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("...類外setup...")
def test_create():
print("類外test_create")
def test_view():
print("類外test_view")
class TestSetupClass:
def setup(self):
print("...類內(nèi)setup...")
def test_create(self):
print("類內(nèi)test_create")
def test_view(self):
print("類內(nèi)test_view")
def teardown(self):
print("...類內(nèi)teardown...")
def teardown():
print("...類外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的使用
新聞來源:http://m.fisionsoft.com.cn/article/djjdspo.html


咨詢
建站咨詢
