pytest框架
1、pytest認識
(1)pytest比unnitest的優(yōu)點:
(2)pytest使用規(guī)則:
測試文件以test_開頭(以test結(jié)尾也可以)
測試類以Test開頭,并且不能帶有init方法
測試函數(shù)以test開頭
(3)安裝3.8.0版本:
pip install pytest==3.8.0
(4)pytest一個簡單的例子
命令行運行結(jié)果:
(1)cd 到代碼所在的目錄,執(zhí)行命令:py.test test_pyexample.py
(2) 安裝pytest-sugar插件可以看到進度條
2、pytest參數(shù)化:@pytest.mark.parametrize()
(1)單個參數(shù)
使用裝飾器:@pytest.mark.parametrize()
@pytest.mark.parametrize('x',[(1),(2),(6)])
(2)多個參數(shù)
@pytest.mark.parametrize('x,y',[
(1+2,3),
(2-0,1),
(62,12),
(102,3),
("test","test"),
])
3、pytest多個assert:pytest-assume
安裝插件:pip install pytest-assume
使用多個assert,結(jié)果中只有第一個錯誤,沒有報出第二個
4、重新運行失敗的用例:pytest- rerunfailures
安裝插件:pip install pytest- rerunfailures
(pytest的安裝路徑)>pytest --reruns n 腳本路徑,
(pytest的安裝路徑)>pytest -s --reruns n 腳本路徑
5、控制測試運行順序:pytest--ordering
安裝插件pip install pytest-ordering
借助于裝飾器@pytest.mark.run(order=1)控制測試運行的順序
@pytest.mark.run(order=1) #先執(zhí)行order=1
@pytest.mark.run(order=2) #后執(zhí)行order=2
pycharm-python項目利用requiresments文件,安裝第三方庫:
pip3 freeze > requirements.txt # 生成requirements.txt
pip3 install -r requirements.txt # 從requirements.txt安裝依賴
參考鏈接
https://blog.csdn.net/yxxxiao/article/details/94591174#%E4%B8%80%E3%80%81%E5%AE%89%E8%A3%85
pytest從基礎(chǔ)到實戰(zhàn)
https://blog.csdn.net/yyang3121/article/details/80624168
也可參照下面鏈接
https://blog.csdn.net/weixin_44275820/article/details/105169871
參考testhome
https://testerhome.com/topics/15649?locale=zh-TW
不錯的貼子
https://blog.csdn.net/weixin_39430584/article/details/95052202
Pytest和Allure測試框架-超詳細版+實戰(zhàn)
https://blog.csdn.net/qq_42610167/article/details/101204066