allure报告官网地址: github.com/allure-fram…
1、下载allure安装包,本地解压后配置系统环境变量,配置完成后。
2、在DOS窗口和开发环境中都要输入:allure命令,查看是否配置allure成功。
allure配置成功验证:
还要在代码环境下执行下:
3、安装allure
pip install allure-pytest
4、生成allure报告
第一步:生成临时的json报告
在pytest.ini文件中添加配置信息:
addopts = -vs --alluredir ./temp --clean-alluredir
--------生成临时的allure 的json报告,且每运行一次就删除之前的临时json报告,配置如下:
[pytest]
addopts = -vs --alluredir ./temp --clean-alluredir
testpaths = ./com/yangying/test_login.py
python_files = test_login.py
python_classes = Test*
python_functions = test_*
第二步:生成html的allure报告
在run.py文件 main函数中添加如下代码,运行run.py文件:
time.sleep(3)
os.system("allure generate ./temp -o ./allure-report --clean") ----------构建allure 的html报告,从临时文件目录temp输出到allure-report目录中
代码如下:
if __name__ == '__main__':
pytest.main() # 加参数是以列表的方式
time.sleep(3)
os.system("allure generate ./temp -o ./allure-report --clean")
第三步:打开allure报告
在项目根目录下allure-report目录中,找到index.html文件,文件右上角以浏览器方式打开,即可打开allure报告。
index.html文件以浏览器打开的allure报告: