一、关于pytest-html安装
pytest-html属于pytest的一个插件,使用它需要先安装
pip install pytest-html
pytest可以生成多种样式的结果:
-
生成JunitXML格式的测试报告,命令:--junitxml=path
-
生成ResultLog格式的测试报告,命令:--resultlog=report/log.txt
-
生成Html格式的测试报告,命令:--html=OutPuts/reports/report.html(相对路径)
二、生成html报告
if __name__ == '__main__':
# 生成python-html报告
pytest.main(['-s', '-v', '--html=OutPuts/reports/report.html'])
一、关于allure安装
allure是跟pytest一起集成使用的,所以需要同时安装pytest以及allure-pytest插件:
pip install pytest
pip install allure-pytest
- 前置条件jdk必须先安装,基于这个环境才能运行
安装allure从Maven Center下载最新的安装包(选择最新版本):
https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline
1.选择zip包:

2.将包解压到任何一个目录,建议不要选C盘或者路径很深的。比如G:\allure-2.13.0
3.跳转到解压后的bin目录下面,windows下执行allure.bat。其它平台执行allure
4.配置allure的环境变量:

5.测试安装是否OK

二、生成allure测试报告文件
使用命令行:—alluredir=Outputs/allure (相对于pytest命令所在目录的测试报告目录)
if __name__ == '__main__':
# 生成allure报告文件
pytest.main(['-s', '-v', '--alluredir=OutPuts/allure'])
所有用例执行完,在OutPuts/allure目录下会生成一些报告文件

三、生成html页面的allure测试报告
1.查看allure报告
使用命令行:allure serve 测试结果文件目录(OutPuts/allure)


2.生成html格式的allure报告
使用命令行:allure generate 测试结果文件目录 -o 输入html文件的目录 --clean
--clean表示每次执行该命令行都先清除输入html文件的目录下的文件
比如:allure generate OutPuts/allure -o OutPuts/allure_html --clean


对该文件右键—>Open in Browser—>Chrome,打开测试报告


pytest.ini 配置
[pytest]
markers =
smoke:marks tests as smoke.
demo:marks tests asa demo.
testpaths=./cases
addopts=-vsq --reruns 2 --html=output/report/html/report.html --alluredir=output/report/allure_report
base_url=https://www.baidu.com/
网友评论