pytest官网:https://docs.pytest.org/en/stable/
可以使用pip安装
pip install pytest # 安装稳定版本 pip install pytest==6.2.1
html报告,需要安装html插件
pip install pytest-html
allure报告,官方网站:https://docs.qameta.io/allure/。allure解析测试结果文件,然后生成多维度数据展示的测试报告。配置如下:
1)pytest生成可供allure解析的测试结果文件,但需要安装allure插件,使用pip安装
注:测试结果文件由必须得是allure能够解析的。
pip install allure-pytest
2)安装allure工具,下载地址:https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.17.2/
windows系统下,我使用的是zip包,将下载的压缩包解压到本地路径
3)将allure的bin目录配置到环境变量path中
allure报告使用方式
1)在Python目录下新建allure报告相关的python package,例如:allure-report-files。注:一定创建python package而不是Directory,不然无法解析测试结果文件。
2)在pytest命令加上参数:–alluredir=/tmp/my_allure_results,此路径是相对rootdir的路径
main.py
import pytest
# 收集用例并执行测试用例
pytest.main(["-s","-v","--html=Pythonbase_01.html",
"--alluredir=allure-report-files"])
3)运行main.py,pytest执行完用例会生成测试结果文件
4)可以在pycharm直接打开终端,cd到当前main.py文件所在的目录下,使用allure命令生成报告:
allure serve allure-report-files # allure-report-files为测试结果文件路径
5)解析完测试结果文件,生成报告后,将自动打开默认浏览器,打开:allure报告,即可查看多维度的测试报告结果
html报告使用方式,在pytest命令加上参数:–html=报告路径.html,运行main.py后,在rootdir目录下看到Pythonbase_01.html,手动使用浏览器打开此文件,可查看测试结果。
main.py
import pytest
# 收集用例并执行测试用例
pytest.main(["-s","-v","--html=Pythonbase_01.html",
"--alluredir=allure-report-files"])



