第一步:pip install pytest-allure-adaptor
第二步:编写用例
import allure
import pytest
"""
Feature: 标注主要功能模块
Story: 标注Features功能模块下的分支功能
Severity: 标注测试用例的重要级别
Step: 标注测试用例的重要步骤
Issue和TestCase: 标注Issue、Case,可加入URL
attach: 标注增加附件
Environment: 标注环境Environment字段
"""
# 环境
allure.MASTER_HELPER.environment(域名="127.0.0.1")
@allure.MASTER_HELPER.feature("测试")
class TestClassOne:
@allure.MASTER_HELPER.story("test_one_1")
@allure.MASTER_HELPER.severity("normal")
# 运行步骤
@allure.MASTER_HELPER.step("单元相当")
def test_one_1(self):
with allure.MASTER_HELPER.step("获取变量a"):
a = 3
with allure.MASTER_HELPER.step("获取变量b"):
b = 2
allure.MASTER_HELPER.attach("预期结果", "{0}".format("1"))
allure.MASTER_HELPER.attach("实际结果", "{0}".format("2"))
x = "this"
assert 't' in x
@allure.MASTER_HELPER.story("test_two_2")
@allure.MASTER_HELPER.severity("normal")
def test_two_2(self):
"""用例描述拉"""
x = "hello"
assert hasattr(x, 'check')
@allure.MASTER_HELPER.story("test_one_1")
@allure.MASTER_HELPER.severity("normal")
def test_one_3(self):
x = "this"
assert 't' in x
@allure.MASTER_HELPER.story("test_two_2")
@allure.MASTER_HELPER.severity("normal")
def test_two_4(self):
x = "hello"
assert hasattr(x, 'check')
@allure.MASTER_HELPER.story("test_one_1")
@allure.MASTER_HELPER.severity("normal")
def test_one_5(self):
x = "this"
assert 't' in x
@allure.MASTER_HELPER.story("test_two_2")
@allure.MASTER_HELPER.severity("normal")
def test_two_6(self):
x = "hello"
assert hasattr(x, 'check')
@allure.MASTER_HELPER.story("test_one_1")
@allure.MASTER_HELPER.severity("trivial")
def test_one_7(self):
x = "this"
assert 't' in x
@allure.MASTER_HELPER.story("test_two_2")
@allure.MASTER_HELPER.severity("normal")
def test_two_8(self):
x = "hello"
assert hasattr(x, 'check')
import os
if __name__ == '__main__':
"""
--reruns 重试
-s 显示print内容
"""
pytest.main(['-s', '--reruns', '10', '-q', 'test_pytestdemo.py', '--alluredir', './report/xml'])
os.system("allure generate report/xml -o report/html")
#执行后自动打开报告 allure serve allure
执行一下命令
生成xml数据
pytest -s -q --alluredir=report
生成报告
allure generate report/ -o report/html