日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

pytest teardown 未执行_python3+pytest+allure框架搭建之pytest详解(一)

發(fā)布時(shí)間:2024/1/23 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。