82 lines
3.3 KiB
Python
82 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
||
# @Time : 2023/3/28 23:17
|
||
# @Author : Flora.Chen
|
||
# @File : conftest.py
|
||
# @Software: PyCharm
|
||
# @Desc:
|
||
|
||
|
||
# 标准库导入
|
||
import os
|
||
# 第三方库导入
|
||
import pytest
|
||
import allure
|
||
from loguru import logger
|
||
# 本地应用/模块导入
|
||
from config.global_vars import GLOBAL_VARS
|
||
from config.path_config import GITLINK_DIR
|
||
from utils.report_utils.allure_handle import allure_title
|
||
from utils.requests_utils.api_workflow import get_api_data, api_work_flow
|
||
from utils.requests_utils.case_dependence import case_dependence_handle
|
||
|
||
|
||
@pytest.fixture(scope="function", autouse=True)
|
||
def case_control(request):
|
||
"""用例控制"""
|
||
# 使用 request.getfixturevalue() 方法来获取测试用例函数的参数值
|
||
# 注意这里的"case"需要与@pytest.mark.parametrize("case", cases)中传递的保持一致
|
||
case = request.getfixturevalue("case")
|
||
logger.info("\n\n-----------------------------START-开始执行用例-----------------------------\n\n")
|
||
# 添加用例标题作为allure中显示的用例标题
|
||
allure_title(case.get("title", ""))
|
||
if case.get("run") is None or case.get("run") is False:
|
||
reason = f"{case.get('title')}: 标记了该用例为false,不执行\\n"
|
||
logger.warning(f"{reason}")
|
||
pytest.skip(reason)
|
||
yield
|
||
logger.info("\n\n-----------------------------END-用例执行完成-----------------------------\n\n")
|
||
|
||
|
||
def pytest_collection_modifyitems(config, items):
|
||
for item in items:
|
||
# 注意这里的"case"需要与@pytest.mark.parametrize("case", cases)中传递的保持一致
|
||
parameters = item.callspec.params["case"]
|
||
# print(f"测试参数:{type(parameters)} {parameters}")
|
||
if parameters.get("severity"):
|
||
if parameters["severity"].upper() == "TRIVIAL":
|
||
item.add_marker(allure.severity(allure.severity_level.TRIVIAL))
|
||
elif parameters["severity"].upper() == "MINOR":
|
||
item.add_marker(allure.severity(allure.severity_level.MINOR))
|
||
elif parameters["severity"].upper() == "CRITICAL":
|
||
item.add_marker(allure.severity(allure.severity_level.CRITICAL))
|
||
elif parameters["severity"].upper() == "BLOCKER":
|
||
item.add_marker(allure.severity(allure.severity_level.BLOCKER))
|
||
else:
|
||
item.add_marker(allure.severity(allure.severity_level.NORMAL))
|
||
else:
|
||
item.add_marker(allure.severity(allure.severity_level.NORMAL))
|
||
|
||
|
||
@pytest.fixture(scope="module")
|
||
def gitlink_login():
|
||
"""
|
||
获取登录的cookie
|
||
:return:
|
||
"""
|
||
# 请求登录接口
|
||
login_api = get_api_data(os.path.join(GITLINK_DIR, "test_gitlink_login.yaml"), "gitlink_login_01")
|
||
res = api_work_flow(login_api, GLOBAL_VARS)
|
||
GLOBAL_VARS.update(res)
|
||
|
||
|
||
@pytest.fixture(scope="session")
|
||
def get_oauth_token():
|
||
"""
|
||
获取oauth_token, 用于在接口的headers里面传递{Authorization:Bearer {{token}}}
|
||
注意:oauth_token适用于application通过客户端的方式登录平台。application不同于正常注册平台的用户,是没有用户名和密码的。
|
||
"""
|
||
login_oauth_token_api = get_api_data(os.path.join(GITLINK_DIR, "login_oauth_token.yaml"),
|
||
"gitlink_login_oauth_token_01")
|
||
|
||
res = api_work_flow(login_oauth_token_api, GLOBAL_VARS)
|
||
GLOBAL_VARS.update(res) |