增加测试框架对allure测试报告的支持,已完成初版,能用户通过-report参数指定生成的是pytest-html报告还是allure报告
This commit is contained in:
@@ -11,11 +11,15 @@ import pytest
|
||||
from loguru import logger
|
||||
from pytest_html import extras # 往pytest-html报告中填写额外的内容
|
||||
from common_utils.func_handle import add_docstring
|
||||
import allure
|
||||
from case_utils.allure_handle import allure_title, allure_step
|
||||
|
||||
# 读取用例数据
|
||||
cases = [{"title": "demo cese_01", "user": "flora", "age": 17, "run": False}]
|
||||
cases = [{"title": "demo case 01", "user": "flora1", "age": 17, "run": True},
|
||||
{"title": "demo case 02", "user": "lucy", "age": 17, "run": True}]
|
||||
|
||||
|
||||
@allure.story("demo模块")
|
||||
@pytest.mark.test_login_demo
|
||||
@pytest.mark.parametrize("case", cases)
|
||||
def test_demo(case, extra):
|
||||
@@ -23,10 +27,14 @@ def test_demo(case, extra):
|
||||
logger.debug(f"当前执行的用例数据:{case}")
|
||||
# 给当前测试方法添加文档注释
|
||||
add_docstring(case.get("title", ""))(test_demo)
|
||||
# 添加用例标题作为allure中显示的用例标题
|
||||
allure_title(case.get("title", ""))
|
||||
if case.get("run", None):
|
||||
assert case["user"] == "flora"
|
||||
# 将用例数据显示在pytest-html报告中
|
||||
extra.append(extras.json(case, name="用例数据"))
|
||||
# 在allure报告中显示请求的用例数据
|
||||
allure_step(step_title="用例数据", content=f"{case}")
|
||||
assert case["user"] == "flora"
|
||||
else:
|
||||
reason = f"标记了该用例为false,不执行\\n"
|
||||
logger.warning(f"{reason}")
|
||||
|
||||
Reference in New Issue
Block a user