1、allure安装
- 安装pytest
pip install pytest
- 安装allure-pytest
pip install allure-pytest
2、下载allure命令行工具
- 1、去github上下载最新版https://github.com/allure-framework/allure2/releases
- 2、下载完成后,解压本地,并匹配环境变量(最好放在path的第一位)
3、allure执行与生成报告
- 执行命令
pytest [py文件] -q -s --alluredir=目标地址
pytest [py文件] -q -s --alluredir 目标地址
- 生成查看报告
# 方法一:
allure serve 目标地址(和上面对应)
# 方法二:
# 生成报告
allure generate ./report/1 ./result/ --clean(如果result不存在会默认创建个allure-report文件夹)
# 打开报告
allure open -h 127.0.0.1 -p 8883 ./allure-report/
4、allure常用特性
场景
希望在测试中看到测试的功能,子功能或场景、测试步骤、附加信息等
解决
@allure.feature、 @allure.story、@allure.step、@allure.attach
步骤
@allure.feature(“功能名称”)
@allure.story(“子功能名称”)
@allure.step(“操作步骤”)
@allure.attach(“具体文本信息”)(可以是文本,图片,网页等)
feature相当于一个功能,一个大模块,将case分配到某个feature中,在报告中behavior中显示,相当于testsuit
story相当于对应这个功能下的子功,不同场景,分支,属于featrue之下的结构,报告在features中显示,相当于testcase
import pytest
import allure
@allure.feature("登录模块")
class TestLogin:
@allure.story("登录成功")
def test_login1(self):
print("登录成功。。。")
@allure.story("登录失败")
def test_login2(self):
print("登录失败。。。")
@allure.story("登录详情")
def test_login3(self):
with allure.step("点击用户名"):
print("输入用户名。。。")
with allure.step("点击密码"):
print("shu输入密码。。。")
with allure.step("点击登录"):
print("点击登录。。。。")
with allure.step("点击登录后,登录失败"):
assert "1" == 1
print("登录失败")
5、bug的等级
- Blocker:中断缺陷(程序无响应,无法进行下一步操作)
- Critical:临界缺陷(功能缺失)
- Normal:正常缺陷(数值计算错误)
- Minor:次等缺陷(界面和UI不符合)
- Trivial:轻微缺陷(输入项无提示文字)
使用 - 在函数、方法上面加@allure.severity_level(allure.severity_level.TRIVIAL)
执行 - pytest -v -s allure-severities normal