pytest teardown 未执行_python3+pytest+allure框架搭建之pytest详解(一)
生活随笔
收集整理的這篇文章主要介紹了
pytest teardown 未执行_python3+pytest+allure框架搭建之pytest详解(一)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前言:之前在網(wǎng)上查了不少關(guān)于pytest的資料,總結(jié)了一下pytest比較重要的點(diǎn):
1、可以更好的控制測試用例
2、支持很多第三方插件,并可以自定義擴(kuò)展
3、執(zhí)行失敗的測試用例可以重復(fù)執(zhí)行
4、可以很好的與jenkins結(jié)合
5、需要遵循pytest框架的一些用例設(shè)計(jì)原則,以便更好的識(shí)別case:
1)測試文件名需要滿足test_*.py或*_test.py文件格式
2)測試類以Test開頭,并且不能帶有 init 方法
3)測試函數(shù)/方法以test_開頭
4)斷言使用assert xxxxx即可
一、斷言
首先從簡單的斷言開始,-s表示執(zhí)行,-q即-quiet,作用是減少冗長,不在展示pytest的版本信息
import pytestdef test_01():print('hello pytest')assert 1>2def test_02():assert 1if __name__ == '__main__':pytest.main(["-s",'-q','test_seven.py'])二、setup/teardown函數(shù)
用法:運(yùn)行于測試方法的始末,并且每個(gè)測試函數(shù)都會(huì)執(zhí)行一次
import pytest#setup_class,teardown_class表示前后只執(zhí)行一次#setup,teardown表示每個(gè)case都執(zhí)行一次class Test_Pytest:def setup(self): print("------->setup")def teardown(self): print("------->teardown")def test_01(self):print('hello pytest')assert 1>2def test_02(self):assert 1 ==1if __name__ == '__main__':pytest.main(['-s','-q','test_six.py'])三、setup_class/teardown_class函數(shù)
用法:運(yùn)行于測試方法的始末,并且每個(gè)測試類都會(huì)執(zhí)行一次
import pytest#setup_class,teardown_class表示前后只執(zhí)行一次#setup,teardown表示每個(gè)case都執(zhí)行一次class Test_one:def setup_class(self): print("------->setup_class")def teardown_class(self): print("------->teardown_class")def test_01(self):print('hello pytest')assert 1>2def test_02(self):assert 1 ==1class Test_two:def setup_class(self):print("=========>setup_class")def teardown_class(self):print("=========>teardown_class")def test_03(self):assert 1def test_04(self):assert 10>100if __name__ == '__main__':pytest.main(['-s','-q','test_six.py'])總結(jié)
上面三點(diǎn)是pytest基本用法,后面會(huì)繼續(xù)介紹pytest的精髓fixture裝飾器
總結(jié)
以上是生活随笔為你收集整理的pytest teardown 未执行_python3+pytest+allure框架搭建之pytest详解(一)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: sqoop增量导出mysql_sqoop
- 下一篇: vueform表单文件上传_峰哥说技术系