是python測試框架
特點:
簡單靈活,文檔豐富
支持參數(shù)化,可以細粒度地控制要測試的測試用例
能夠支持簡單的單元測試和復(fù)雜的功能測試,還可以用來做selenium/appnium等自動化測試、接口自動化測試(pytest+requests)
pytest具有很多第三方插件,并且可以自定義擴展,比較好的如pytest-selenium(集成selenium),pytest-html(完美html測試報告生成)、pytest-rerunfailures(失敗case重復(fù)執(zhí)行)、pytest-xdist(多CPU分發(fā))等;
測試用例的skip和xfail處理
可以很好的和CI工具結(jié)合,例如Jenkins
安裝:
pip install pytest
pytest官網(wǎng):
https://docs.pytest.org/en/stable/
編寫規(guī)則:
測試文件以test開頭(以test結(jié)尾也可以)
測試類以Test開頭,并且不能帶有init方法
測試函數(shù)以test開頭
斷言使用基本的assert即可
Console參數(shù)介紹
-v 用于顯示每個測試函數(shù)的執(zhí)行結(jié)果
-q 只顯示整體測試結(jié)果
-s 用于顯示測試函數(shù)中print()函數(shù)輸出
-x,--exitfirst,在第一個錯誤或測試失敗時立即退出
-h 幫助
執(zhí)行測試
配置pycharm執(zhí)行:Tools-->Python Integrated tools -->Default test runner
main方法:pytest.main(['-s','-v','01-pytest簡介.py'])
命令行:pytest -s -v test.py