所需插件自行安装,后面整理同步这篇文章中
所需插件:
pytest
allure_pytest
pytest-xdist
第一种方式,通过pytest.main()的方式运行,如下图所示
import pytest if __name__ == '__main__': # -v详细到用例 -s打印信息 “test_cases/”指运行test_cases文件夹下 # pytest.main(["-vs", "test_cases/"]) # -x 遇到一次错误便停止 --maxfail=n 遇到n次错误停止 # pytest.main(["-x", "--maxfail=2"]) # -n n线程运行(需要先安装pytest-xdist) --html=路径/report.html:生成xml/html格式测试报告(需要先安装pytest-html) # pytest.main(["-n", "--html=report/report.html"]) # -reruns = n 遇到错误重复运行n次 #pytest.main(["-vs", "test_cases", "-reruns = 2"])
需要注意的点:
1.参数需要加中括号[]
2.参数有的需要一个-,有的需要两个-
3.上述参数并非需要多个参数一起执行,单个参数依旧可以执行
4.此方式运行如果不指定扫描路径是会对当前项目所有符合条件的用例进行执行