欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

簡(jiǎn)單了解pytest測(cè)試框架setup和tearDown

 更新時(shí)間:2020年04月14日 12:01:29   作者:seyOrd  
這篇文章主要介紹了簡(jiǎn)單了解pytest測(cè)試框架setup和tearDown,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

pytest的setup與teardown

1)pytest提供了兩套互相獨(dú)立的setup 與 teardown和一對(duì)相對(duì)自由的setup與teardown

2)模塊級(jí)與函數(shù)級(jí)

  模塊級(jí)(setup_module/teardown_module)  #開(kāi)始于模塊始末(不在類中)

  函數(shù)級(jí)(setup_function/teardown_function)  #只對(duì)函數(shù)用例生效(不在類中)

3)方法級(jí)與類級(jí)

  方法級(jí)(setup_method/teardown_method)  #開(kāi)始于方法始末(在類中)

  類級(jí)(setup_class/teardown_class)     #只在類中前后運(yùn)行一次(在類中)

3)類里面的(setup/teardown)           #運(yùn)行在調(diào)用方法的前后

setup與teardown例子

import pytest
# 模塊中的方法
def setup_module():
	print(
		"setup_module:整個(gè)test_module.py模塊只執(zhí)行一次"
	)
def teardown_module():
	print(
		"teardown_module:整個(gè)test_module.py模塊只執(zhí)行一次"
	)
def setup_function():
	print("setup_function:每個(gè)用例開(kāi)始前都會(huì)執(zhí)行")
def teardown_function():
	print("teardown_function:每個(gè)用例結(jié)束后都會(huì)執(zhí)行")
# 測(cè)試模塊中的用例1
def test_one():
	print("正在執(zhí)行測(cè)試模塊----test_one")
# 測(cè)試模塊中的用例2
def test_two():
	print("正在執(zhí)行測(cè)試模塊----test_two")
# 測(cè)試類
class TestCase():
	def setup_class(self):
	print("setup_class:所有用例執(zhí)行之前")
def teardown_class(self):
	print("teardown_class:所有用例執(zhí)行之后")   def setup_method(
		self):
	print("setup_method: 每個(gè)用例開(kāi)始前執(zhí)行")
def teardown_method(self):
	print("teardown_method: 每個(gè)用例結(jié)束后執(zhí)行")
def setup(self):
	print("setup:每個(gè)用例開(kāi)始前都會(huì)執(zhí)行")
def teardown(self):
	print("teardown:每個(gè)用例結(jié)束后都會(huì)執(zhí)行")
def test_three(self):
	print("正在執(zhí)行測(cè)試類----test_three")
def test_four(self):
	print("正在執(zhí)行測(cè)試類----test_four")
if __name__ == "__main__":
	pytest.main(["-s", "test_module.py"])

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論