一.安装allure-pytest包
两种方式任选其一:
1.pip install allure-pytest
2.pip install -i https://pypi.douban.com/simple allure-pytest
二.安装allure对应的环境
1.安装jdk并配置环境
https://www.jb51.net/softs/604550.html
2.下载allure并配置环境
百度云盘地址:链接:https://pan.baidu.com/s/1aop24DHNcOlOKFUH7waqVA 提取码:v7he
解压到任意盘下,将加压目录下的bin和lib文件夹设置为环境变量
cmd执行allure --version 显示:2.10.0版本
三.生成allure报告对应的源文件
1.执行全部
pytest --alluredir=./reports --clean-alluredir
注释:
- –alluredir=./report:指定allure源文件的目录地址为./reports
- –clean-alluredir:如果已经有指定目录就删除
2.执行指定类
pytest testcases/test_base_page.py::TestBase --alluredir=./reports --clean-alluredir
四.查看allure的报告
1.进入到项目目录,在cmd(不然会发生意料之外的错误)环境下执行
allure serve reports
注释:
- allure:关键字
- serve:关键字
- report:源文件的目录
2.生成本地文件
allure generate ./reports -o ./reports/html -c ./reports/html
注释:
- allure:关键字
- generate:关键字
- ./reports:源文件的目录
- -o ./report/html:生成文件的目录
- -c ./report/html:如果文件已存在则删除
3.运行多个模块下的多个测试case方法
pytest.main(
[’-s’, ‘-k’, ‘test_establish_connection or test_order_runner’, “–alluredir=report/allure_result”])