国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

網(wǎng)站建設(shè)運(yùn)營協(xié)議書2023年6月份又封城了

網(wǎng)站建設(shè)運(yùn)營協(xié)議書,2023年6月份又封城了,網(wǎng)站 維護(hù)方案,團(tuán)購網(wǎng)站怎么做這里寫目錄標(biāo)題一、pytest用法總結(jié)二、pytest.ini是什么三、改變運(yùn)行規(guī)則pytest.inicheck_demo.py執(zhí)行測試用例四、添加默認(rèn)參數(shù)五、指定執(zhí)行目錄六、日志配置七、pytest插件分類八、pytest常用插件九、改變測試用例的執(zhí)行順序十、pytest并行與分布式執(zhí)行十一、pytest內(nèi)置插件h…

在這里插入圖片描述


這里寫目錄標(biāo)題

  • 一、pytest用法總結(jié)
  • 二、pytest.ini是什么
  • 三、改變運(yùn)行規(guī)則
    • pytest.ini
    • check_demo.py
    • 執(zhí)行測試用例
  • 四、添加默認(rèn)參數(shù)
  • 五、指定執(zhí)行目錄
  • 六、日志配置
  • 七、pytest插件分類
  • 八、pytest常用插件
  • 九、改變測試用例的執(zhí)行順序
  • 十、pytest并行與分布式執(zhí)行
  • 十一、pytest內(nèi)置插件hook體系
  • 十二、pytest插件開發(fā)
    • 1、pytest_collection_modifyitems
    • 2、pytest編寫插件——添加命令行參數(shù)(***)
      • conftest.py
      • test_option.py

一、pytest用法總結(jié)

1、修改用例的命名規(guī)則
2、配置日志格式、比代碼配置更方便
3、指定執(zhí)行目錄
4、排除搜索目錄
5、添加標(biāo)簽,防止運(yùn)行過程報警告
6、添加默認(rèn)參數(shù)

二、pytest.ini是什么

pytest.ini是pytest的配置文件
可以修改pytest的默認(rèn)行為
不能使用任何中文字符,包括漢字、空格、中文引號、中文冒號、中文注釋

三、改變運(yùn)行規(guī)則

執(zhí)行check_開頭和 test_開頭的所有的文件,后面一定要加*
python_files = check * test *
執(zhí)行所有的以Test和Check開頭的類
python_classes = Test* Check*
執(zhí)行所有以test_和check_開頭的方法
python_functions= test_* check_*

pytest.ini

pytest.ini中不能加注釋

在這里插入圖片描述

check_demo.py

import pytest
import loggingclass CheckDemo:def check_demo1(self):logging.info('這是demo1測試用例')assert 1==1def check_demo2(self):logging.info('這是demo1測試用例')assert 1==1def test_demo1(self):logging.info('這是demo1測試用例')assert 1==2

執(zhí)行測試用例

pytest check_demo.py

在這里插入圖片描述

四、添加默認(rèn)參數(shù)

addopts = -v -s

五、指定執(zhí)行目錄

testpaths= demo1
忽略某些目錄
norecursedirs = demo1 test_demo

六、日志配置

在這里插入圖片描述

七、pytest插件分類

外部插件:pip install 插件
本地插件:pytest自動發(fā)現(xiàn)機(jī)制(conftest/py存放)
內(nèi)置插件:代碼內(nèi)部的_pytest目錄加載

八、pytest常用插件

pip install pytest-ordering:控制用例執(zhí)行順序
pip install pytest-xdist:分布式并發(fā)執(zhí)行測試用例
pip install pytest-dependency:控制用例的依賴關(guān)系
pip install pytest-rerunfailures:用例失敗重跑
pip install pytest-assume:多重校驗
pip install pytest-random-order:用例隨機(jī)執(zhí)行
pip install pytest-html:測試報告

九、改變測試用例的執(zhí)行順序

安裝;pip install pytest-ordering
使用:裝飾器:@pytest.mark.run(order=num),安裝數(shù)字從小到大的順序執(zhí)行。
pytest默認(rèn)從上到下執(zhí)行測試用例

import pytestclass TestB:@pytest.mark.run(order=2)def test_c(self):pass@pytest.mark.run(order=1)def test_d(self):pass

執(zhí)行測試用例
在這里插入圖片描述

十、pytest并行與分布式執(zhí)行

安裝:pip install xdist
注意:用例多的時候效果明顯,多進(jìn)程并發(fā)執(zhí)行,同時支持allure

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/2/16 21:15
# @Author  : 杜蘭特
# @File    : test_xdist.py
import timeimport pytestclass TestC:def test_e(self):time.sleep(1)assert Truedef test_f(self):time.sleep(1)assert Truedef test_g(self):time.sleep(1)assert Truedef test_e1(self):time.sleep(1)assert Truedef test_f2(self):time.sleep(1)assert Truedef test_g3(self):time.sleep(1)assert True

執(zhí)行測試用例
-n auto:電腦默認(rèn)cpu核數(shù)

D:\pytest_project>pytest -n auto

十一、pytest內(nèi)置插件hook體系

1、hook函數(shù)名字固定
2、hook函數(shù)會被自動執(zhí)行
3、執(zhí)行是有先后順序的
4、pytest定義了很多hook函數(shù),可以在不同階段實現(xiàn)不同的功能
5、pytest有很多鉤子函數(shù)
6、使用時直接編寫函數(shù)體

十二、pytest插件開發(fā)

pytest_collection_modifyitems收集上來的測試用例實現(xiàn)定制化功能
解決問題:
自定義用例的執(zhí)行順序
解決編碼問題(中文的測試用例名稱)
自動添加標(biāo)簽

1、pytest_collection_modifyitems

# 收集完測試用例  之后調(diào)用的hook函數(shù)
def pytest_collection_modifyitems(items):"""測試用例收集完成時,將收集到的用例名name和用例標(biāo)識nodeid的中文信息顯示在控制臺上"""print(items)#name:用例的名字#nodeid:測試用例的路徑for item in items:item.name=item.name.encode('utf-8').decode('unicode-escape')item._nodeid=item.nodeid.encode('utf-8').decode('unicode-escape')items.reverse()

2、pytest編寫插件——添加命令行參數(shù)(***)

conftest.py

#定義一個命令行參數(shù)
def pytest_addoption(parser):mygroup = parser.getgroup("work") #group將下面所有的 option都展示在這個group下。mygroup.addoption("--env",               #注冊一個命令行選項default = 'test',                   # 參數(shù)的默認(rèn)值dest = 'env',               # 存儲的變量 為屬性命令,可以使用option對象訪問到這個值,暫用不到help = 'set your run env'   # 幫助提示 參數(shù)的描述信息)#如何針對傳入的不同參數(shù)完成不同的邏輯處理
@pytest.fixture(scope='session')
def cmdoption(request):myenv=request.config.getoption('--env',default='test')if myenv == 'test':datapath='datas/test.yaml'elif myenv == 'dev':datapath='datas/env.yaml'with open(datapath) as f:datas=yaml.safe_load(f)return myenv,datas

test_option.py

def test_addoption(cmdoption):print(cmdoption)

如果命令行不傳–env參數(shù),env環(huán)境默認(rèn)為test
在這里插入圖片描述

env環(huán)境需要dev的環(huán)境數(shù)據(jù),命令行傳入–env dev

D:\pytest_project\demo_plugin1>pytest test_option.py --env dev

在這里插入圖片描述


在這里插入圖片描述

http://aloenet.com.cn/news/32633.html

相關(guān)文章:

  • 政府門戶網(wǎng)站建設(shè)方案下載磁力吧ciliba
  • 做會計網(wǎng)站的流程seo課程總結(jié)怎么寫
  • 美橙域名查詢網(wǎng)站做網(wǎng)站建設(shè)優(yōu)化的公司排名
  • 做網(wǎng)站空間 阿里云優(yōu)化大師怎么刪除學(xué)生
  • wordpress以前版本星巴克seo網(wǎng)絡(luò)推廣
  • 西安誰家的集團(tuán)門戶網(wǎng)站建設(shè)比較好seo推廣排名重要嗎
  • 做ppt的模板的網(wǎng)站有哪些如何優(yōu)化網(wǎng)站
  • 網(wǎng)站推廣服務(wù)網(wǎng)站連鎖微信朋友圈廣告30元 1000次
  • 湛江免費(fèi)建站模板短視頻剪輯培訓(xùn)班多少錢
  • 剛建的網(wǎng)站百度搜不到聯(lián)合早報 即時消息
  • 推廣網(wǎng)站怎么建設(shè)和維護(hù)seo資訊
  • 產(chǎn)品外包裝設(shè)計網(wǎng)站直通車關(guān)鍵詞優(yōu)化
  • 鄭州天梯網(wǎng)站制作seo研究協(xié)會
  • wordpress左邊欄網(wǎng)頁seo優(yōu)化
  • 哪家公司建網(wǎng)站好推廣代理平臺
  • 開州快速建網(wǎng)站江蘇網(wǎng)頁定制
  • 外包做網(wǎng)站賺錢么讓手機(jī)變流暢的軟件下載
  • 網(wǎng)站站內(nèi)消息設(shè)計方案優(yōu)化大師官方
  • 個人網(wǎng)站建站指南營銷策劃書模板
  • 網(wǎng)站創(chuàng)建時間查詢怎樣推廣app別人才愿意下載
  • 網(wǎng)站建設(shè)banner內(nèi)部優(yōu)化
  • 做國外百科知識網(wǎng)站百度代理查詢
  • 網(wǎng)站動態(tài)海報效果怎么做的寧波seo搜索引擎優(yōu)化公司
  • 做網(wǎng)頁賺錢seo排名優(yōu)化方式
  • 淘寶購物券網(wǎng)站怎么做童程童美少兒編程怎樣收費(fèi)
  • 哪里有網(wǎng)站建設(shè)多少錢百度問一問付費(fèi)咨詢
  • 西寧網(wǎng)站建設(shè)嘉薦君博lseo優(yōu)化的主要內(nèi)容
  • wap歌詞廊坊seo推廣
  • 服務(wù)器 網(wǎng)站 app網(wǎng)絡(luò)營銷的收獲與體會
  • 汽車做網(wǎng)站廣州網(wǎng)站建設(shè)推薦