diff --git a/httpfpt/common/log.py b/httpfpt/common/log.py index 4b71b90..c48ce1a 100644 --- a/httpfpt/common/log.py +++ b/httpfpt/common/log.py @@ -9,7 +9,7 @@ from loguru import logger -from httpfpt.core.path_conf import LOG_PATH +from httpfpt.core.path_conf import httpfpt_path if TYPE_CHECKING: import loguru @@ -28,7 +28,7 @@ def log() -> loguru.Logger: :return: """ - log_path = LOG_PATH + log_path = httpfpt_path.log_dir if not os.path.join(log_path): os.makedirs(log_path) diff --git a/httpfpt/common/send_request.py b/httpfpt/common/send_request.py index 7228d0d..695b67f 100644 --- a/httpfpt/common/send_request.py +++ b/httpfpt/common/send_request.py @@ -15,7 +15,7 @@ from httpfpt.common.errors import AssertError, SendRequestError from httpfpt.common.log import log -from httpfpt.core.get_conf import config +from httpfpt.core.get_conf import httpfpt_config from httpfpt.db.mysql_db import mysql_client from httpfpt.enums.request.body import BodyType from httpfpt.enums.request.engin import EnginType @@ -63,11 +63,11 @@ def _requests_engin(**kwargs) -> RequestsResponse: :param kwargs: :return: """ - kwargs['timeout'] = kwargs['timeout'] or config.REQUEST_TIMEOUT - kwargs['verify'] = kwargs['verify'] or config.REQUEST_VERIFY - kwargs['proxies'] = kwargs['proxies'] or config.REQUEST_PROXIES_REQUESTS - kwargs['allow_redirects'] = kwargs['allow_redirects'] or config.REQUEST_REDIRECTS - request_retry = kwargs['retry'] or config.REQUEST_RETRY + kwargs['timeout'] = kwargs['timeout'] or httpfpt_config.REQUEST_TIMEOUT + kwargs['verify'] = kwargs['verify'] or httpfpt_config.REQUEST_VERIFY + kwargs['proxies'] = kwargs['proxies'] or httpfpt_config.REQUEST_PROXIES_REQUESTS + kwargs['allow_redirects'] = kwargs['allow_redirects'] or httpfpt_config.REQUEST_REDIRECTS + request_retry = kwargs['retry'] or httpfpt_config.REQUEST_RETRY del kwargs['retry'] # 消除安全警告 requests.packages.urllib3.disable_warnings() # type: ignore @@ -93,11 +93,11 @@ def _httpx_engin(**kwargs) -> HttpxResponse: :param kwargs: :return: """ - kwargs['timeout'] = kwargs['timeout'] or config.REQUEST_TIMEOUT - verify = kwargs['verify'] or config.REQUEST_VERIFY - proxies = kwargs['proxies'] or config.REQUEST_PROXIES_HTTPX - redirects = kwargs['allow_redirects'] or config.REQUEST_REDIRECTS - request_retry = kwargs['retry'] or config.REQUEST_RETRY + kwargs['timeout'] = kwargs['timeout'] or httpfpt_config.REQUEST_TIMEOUT + verify = kwargs['verify'] or httpfpt_config.REQUEST_VERIFY + proxies = kwargs['proxies'] or httpfpt_config.REQUEST_PROXIES_HTTPX + redirects = kwargs['allow_redirects'] or httpfpt_config.REQUEST_REDIRECTS + request_retry = kwargs['retry'] or httpfpt_config.REQUEST_RETRY del kwargs['verify'] del kwargs['proxies'] del kwargs['allow_redirects'] diff --git a/httpfpt/common/yaml_handler.py b/httpfpt/common/yaml_handler.py index e2da4d7..220cb15 100644 --- a/httpfpt/common/yaml_handler.py +++ b/httpfpt/common/yaml_handler.py @@ -10,7 +10,7 @@ import yaml from httpfpt.common.log import log -from httpfpt.core.path_conf import TEST_DATA_PATH, YAML_REPORT_PATH +from httpfpt.core.path_conf import httpfpt_path from httpfpt.utils.time_control import get_current_time @@ -78,7 +78,7 @@ def write_yaml_report( :param mode: 文件写入模式 :return """ - _yaml_report_path = YAML_REPORT_PATH + _yaml_report_path = httpfpt_path.yaml_report_dir if not os.path.exists(_yaml_report_path): os.makedirs(_yaml_report_path) _file = os.path.join(_yaml_report_path, filename) @@ -99,9 +99,9 @@ def write_yaml_vars(data: dict) -> None: :param data: :return: """ - _file = os.path.join(TEST_DATA_PATH, 'global_vars.yaml') + _file = os.path.join(httpfpt_path.data_dir, 'global_vars.yaml') try: - _vars = read_yaml(TEST_DATA_PATH, filename='global_vars.yaml') + _vars = read_yaml(httpfpt_path.data_dir, filename='global_vars.yaml') _vars.update(data) with open(_file, encoding='utf-8', mode='w') as f: yaml.dump(_vars, f, allow_unicode=True) diff --git a/httpfpt/conftest.py b/httpfpt/conftest.py index ba94a56..9ba658f 100644 --- a/httpfpt/conftest.py +++ b/httpfpt/conftest.py @@ -11,7 +11,7 @@ from httpfpt.common.log import log from httpfpt.common.variable_cache import variable_cache from httpfpt.common.yaml_handler import write_yaml_report -from httpfpt.core.get_conf import config as sys_config +from httpfpt.core.get_conf import httpfpt_config @pytest.fixture(scope='session', autouse=True) @@ -62,7 +62,7 @@ def pytest_configure(config): if metadata: from pytest_metadata.plugin import metadata_key - config.stash[metadata_key]['Project Name'] = sys_config.PROJECT_NAME + config.stash[metadata_key]['Project Name'] = httpfpt_config.PROJECT_NAME del config.stash[metadata_key]['Packages'] del config.stash[metadata_key]['Platform'] del config.stash[metadata_key]['Plugins'] @@ -76,7 +76,7 @@ def pytest_html_results_summary(prefix): :return: """ # 向 html 报告中的 summary 添加额外信息 - prefix.extend([html.p(f'Tester: {sys_config.TESTER_NAME}')]) + prefix.extend([html.p(f'Tester: {httpfpt_config.TESTER_NAME}')]) @pytest.mark.optionalhook @@ -87,7 +87,7 @@ def pytest_html_report_title(report): :param report: :return: """ - report.title = f'{sys_config.TEST_REPORT_TITLE}' + report.title = f'{httpfpt_config.TEST_REPORT_TITLE}' @pytest.mark.optionalhook diff --git a/httpfpt/core/get_conf.py b/httpfpt/core/get_conf.py index 4bbf5e0..85d9f91 100644 --- a/httpfpt/core/get_conf.py +++ b/httpfpt/core/get_conf.py @@ -8,103 +8,103 @@ from httpfpt.common.toml_handler import read_toml -class Config: +class HttpFptConfig: def __init__(self) -> None: - self.__config = read_toml(str(Path(__file__).resolve().parent), 'conf.toml') + self.settings = read_toml(str(Path(__file__).resolve().parent), 'conf.toml') # 项目目录名 - self.PROJECT_NAME = glom(self.__config, 'project.name') + self.PROJECT_NAME = glom(self.settings, 'project.name') # 测试报告 - self.TEST_REPORT_TITLE = glom(self.__config, 'report.title') - self.TESTER_NAME = glom(self.__config, 'report.tester_name') + self.TEST_REPORT_TITLE = glom(self.settings, 'report.title') + self.TESTER_NAME = glom(self.settings, 'report.tester_name') # mysql 数据库 - self.MYSQL_HOST = glom(self.__config, 'mysql.host') - self.MYSQL_PORT = glom(self.__config, 'mysql.port') - self.MYSQL_USER = glom(self.__config, 'mysql.user') - self.MYSQL_PASSWORD = glom(self.__config, 'mysql.password') - self.MYSQL_DATABASE = glom(self.__config, 'mysql.database') - self.MYSQL_CHARSET = glom(self.__config, 'mysql.charset') + self.MYSQL_HOST = glom(self.settings, 'mysql.host') + self.MYSQL_PORT = glom(self.settings, 'mysql.port') + self.MYSQL_USER = glom(self.settings, 'mysql.user') + self.MYSQL_PASSWORD = glom(self.settings, 'mysql.password') + self.MYSQL_DATABASE = glom(self.settings, 'mysql.database') + self.MYSQL_CHARSET = glom(self.settings, 'mysql.charset') # redis 数据库 - self.REDIS_HOST = glom(self.__config, 'redis.host') - self.REDIS_PORT = glom(self.__config, 'redis.port') - self.REDIS_PASSWORD = glom(self.__config, 'redis.password') - self.REDIS_DATABASE = glom(self.__config, 'redis.database') - self.REDIS_TIMEOUT = glom(self.__config, 'redis.timeout') + self.REDIS_HOST = glom(self.settings, 'redis.host') + self.REDIS_PORT = glom(self.settings, 'redis.port') + self.REDIS_PASSWORD = glom(self.settings, 'redis.password') + self.REDIS_DATABASE = glom(self.settings, 'redis.database') + self.REDIS_TIMEOUT = glom(self.settings, 'redis.timeout') # 邮件 - self.EMAIL_SERVER = glom(self.__config, 'email.host') - self.EMAIL_PORT = glom(self.__config, 'email.port') - self.EMAIL_USER = glom(self.__config, 'email.user') - self.EMAIL_PASSWORD = glom(self.__config, 'email.password') - self.EMAIL_SEND_TO = glom(self.__config, 'email.receiver') - self.EMAIL_SSL = glom(self.__config, 'email.ssl') - self.EMAIL_SEND = glom(self.__config, 'email.send') + self.EMAIL_SERVER = glom(self.settings, 'email.host') + self.EMAIL_PORT = glom(self.settings, 'email.port') + self.EMAIL_USER = glom(self.settings, 'email.user') + self.EMAIL_PASSWORD = glom(self.settings, 'email.password') + self.EMAIL_SEND_TO = glom(self.settings, 'email.receiver') + self.EMAIL_SSL = glom(self.settings, 'email.ssl') + self.EMAIL_SEND = glom(self.settings, 'email.send') # 钉钉 - self.DINGDING_WEBHOOK = glom(self.__config, 'dingding.webhook') + self.DINGDING_WEBHOOK = glom(self.settings, 'dingding.webhook') self.DINGDING_PROXY = { - 'http': glom(self.__config, 'dingding.proxies.http') - if glom(self.__config, 'dingding.proxies.http') != '' + 'http': glom(self.settings, 'dingding.proxies.http') + if glom(self.settings, 'dingding.proxies.http') != '' else None, - 'https': glom(self.__config, 'dingding.proxies.https') - if glom(self.__config, 'dingding.proxies.https') != '' + 'https': glom(self.settings, 'dingding.proxies.https') + if glom(self.settings, 'dingding.proxies.https') != '' else None, } - self.DINGDING_SEND = glom(self.__config, 'dingding.send') + self.DINGDING_SEND = glom(self.settings, 'dingding.send') # 飞书 - self.FEISHU_WEBHOOK = glom(self.__config, 'feishu.webhook') + self.FEISHU_WEBHOOK = glom(self.settings, 'feishu.webhook') self.FEISHU_PROXY = { - 'http': glom(self.__config, 'feishu.proxies.http') - if glom(self.__config, 'feishu.proxies.http') != '' + 'http': glom(self.settings, 'feishu.proxies.http') + if glom(self.settings, 'feishu.proxies.http') != '' else None, - 'https': glom(self.__config, 'feishu.proxies.https') - if glom(self.__config, 'feishu.proxies.https') != '' + 'https': glom(self.settings, 'feishu.proxies.https') + if glom(self.settings, 'feishu.proxies.https') != '' else None, } - self.FEISHU_SEND = glom(self.__config, 'feishu.send') + self.FEISHU_SEND = glom(self.settings, 'feishu.send') # 企业微信 - self.WECHAT_WEBHOOK = glom(self.__config, 'wechat.webhook') + self.WECHAT_WEBHOOK = glom(self.settings, 'wechat.webhook') self.WECHAT_PROXY = { - 'http': glom(self.__config, 'wechat.proxies.http') - if glom(self.__config, 'wechat.proxies.http') != '' + 'http': glom(self.settings, 'wechat.proxies.http') + if glom(self.settings, 'wechat.proxies.http') != '' else None, - 'https': glom(self.__config, 'wechat.proxies.https') - if glom(self.__config, 'wechat.proxies.https') != '' + 'https': glom(self.settings, 'wechat.proxies.https') + if glom(self.settings, 'wechat.proxies.https') != '' else None, } - self.WECHAT_SEND = glom(self.__config, 'wechat.send') + self.WECHAT_SEND = glom(self.settings, 'wechat.send') # 请求发送 - self.REQUEST_TIMEOUT = glom(self.__config, 'request.timeout') - self.REQUEST_VERIFY = glom(self.__config, 'request.verify') - self.REQUEST_REDIRECTS = glom(self.__config, 'request.redirects') + self.REQUEST_TIMEOUT = glom(self.settings, 'request.timeout') + self.REQUEST_VERIFY = glom(self.settings, 'request.verify') + self.REQUEST_REDIRECTS = glom(self.settings, 'request.redirects') self.REQUEST_PROXIES_REQUESTS = { - 'http': glom(self.__config, 'request.proxies.http') - if glom(self.__config, 'request.proxies.http') != '' + 'http': glom(self.settings, 'request.proxies.http') + if glom(self.settings, 'request.proxies.http') != '' else None, - 'https': glom(self.__config, 'request.proxies.https') - if glom(self.__config, 'request.proxies.https') != '' + 'https': glom(self.settings, 'request.proxies.https') + if glom(self.settings, 'request.proxies.https') != '' else None, } self.REQUEST_PROXIES_HTTPX = { - 'http://': glom(self.__config, 'request.proxies.http') - if glom(self.__config, 'request.proxies.http') != '' + 'http://': glom(self.settings, 'request.proxies.http') + if glom(self.settings, 'request.proxies.http') != '' else None, - 'https://': glom(self.__config, 'request.proxies.https') - if glom(self.__config, 'request.proxies.https') != '' + 'https://': glom(self.settings, 'request.proxies.https') + if glom(self.settings, 'request.proxies.https') != '' else None, } - self.REQUEST_RETRY = glom(self.__config, 'request.retry') + self.REQUEST_RETRY = glom(self.settings, 'request.retry') @lru_cache(maxsize=None) -def cache_config() -> Config: - return Config() +def cache_httpfpt_config() -> HttpFptConfig: + return HttpFptConfig() -config = cache_config() +httpfpt_config = cache_httpfpt_config() diff --git a/httpfpt/core/path_conf.py b/httpfpt/core/path_conf.py index 01a2321..930f648 100644 --- a/httpfpt/core/path_conf.py +++ b/httpfpt/core/path_conf.py @@ -2,46 +2,89 @@ # -*- coding: utf-8 -*- import os -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) +from functools import lru_cache -# 获取日志路径 -LOG_PATH = os.path.join(BASE_DIR, 'log') -# 测试数据路径 -TEST_DATA_PATH = os.path.join(BASE_DIR, 'data') +class HttpFptPathConfig: + @property + def project_dir(self) -> str: + _base_dir = os.path.dirname(os.path.dirname(__file__)) + return _base_dir -# Yaml测试数据路径 -CASE_DATA_PATH = os.path.join(TEST_DATA_PATH, 'test_data') + @property + def log_dir(self) -> str: + """日志路径""" + return os.path.join(self.project_dir, 'log') -# 测试报告路径 -TEST_REPORT_PATH = os.path.join(BASE_DIR, 'report') + @property + def data_dir(self) -> str: + """数据路径""" + return os.path.join(self.project_dir, 'data') -# allure测试报告路径 -ALLURE_REPORT_PATH = os.path.join(TEST_REPORT_PATH, 'allure_report') + @property + def case_data_dir(self) -> str: + """用例数据路径""" + return os.path.join(self.data_dir, 'test_data') -# allure html测试报告路径 -ALLURE_REPORT_HTML_PATH = os.path.join(ALLURE_REPORT_PATH, 'html') + @property + def report_dir(self) -> str: + """测试报告路径""" + return os.path.join(self.project_dir, 'report') -# HTML测试报告路径 -HTML_REPORT_PATH = os.path.join(TEST_REPORT_PATH, 'html_report') + @property + def allure_report_dir(self) -> str: + """allure测试报告路径""" + return os.path.join(self.report_dir, 'allure_report') -# HTML测试报告路径 -HTML_EMAIL_REPORT_PATH = os.path.join(BASE_DIR, 'templates') + @property + def allure_html_report_dir(self) -> str: + """allure html测试报告路径""" + return os.path.join(self.allure_report_dir, 'html') -# YAML测试报告路径 -YAML_REPORT_PATH = os.path.join(TEST_REPORT_PATH, 'yaml_report') + @property + def html_report_dir(self) -> str: + """HTML测试报告路径""" + return os.path.join(self.report_dir, 'html_report') -# allure环境文件 -ALLURE_ENV_FILE = os.path.join(BASE_DIR, 'core', 'allure_env', 'environment.properties') + @property + def html_email_report_dir(self) -> str: + """html邮箱报告路径""" + return os.path.join(self.project_dir, 'templates') -# allure报告环境文件,用作copy,避免allure开启清理缓存导致环境文件丢失 -ALLURE_REPORT_ENV_FILE = os.path.join(ALLURE_REPORT_PATH, 'environment.properties') + @property + def yaml_report_dir(self) -> str: + """YAML测试报告路径""" + return os.path.join(self.report_dir, 'yaml_report') -# 运行环境文件路径 -RUN_ENV_PATH = os.path.join(BASE_DIR, 'core', 'run_env') + @property + def allure_env_file(self) -> str: + """allure环境文件""" + return os.path.join(self.project_dir, 'core', 'allure_env', 'environment.properties') -# 测试用例路径 -TEST_CASE_PATH = os.path.join(BASE_DIR, 'testcases') + @property + def allure_report_env_file(self) -> str: + """allure报告环境文件,用作copy,避免allure开启清理缓存导致环境文件丢失""" + return os.path.join(self.allure_report_dir, 'environment.properties') -# AUTH配置文件路径 -AUTH_CONF_PATH = os.path.join(BASE_DIR, 'core') + @property + def run_env_dir(self) -> str: + """运行环境文件路径""" + return os.path.join(self.project_dir, 'core', 'run_env') + + @property + def testcase_dir(self) -> str: + """测试用例路径""" + return os.path.join(self.project_dir, 'testcases') + + @property + def auth_conf_dir(self) -> str: + """AUTH配置文件路径""" + return os.path.join(self.project_dir, 'core') + + +@lru_cache(maxsize=None) +def cache_httpfpt_path() -> HttpFptPathConfig: + return HttpFptPathConfig() + + +httpfpt_path = cache_httpfpt_path() diff --git a/httpfpt/db/mysql_db.py b/httpfpt/db/mysql_db.py index 42b6de9..5cb95c4 100644 --- a/httpfpt/db/mysql_db.py +++ b/httpfpt/db/mysql_db.py @@ -13,7 +13,7 @@ from httpfpt.common.errors import SQLSyntaxError from httpfpt.common.log import log -from httpfpt.core.get_conf import config +from httpfpt.core.get_conf import httpfpt_config from httpfpt.enums.query_fetch_type import QueryFetchType from httpfpt.enums.sql_type import SqlType from httpfpt.utils.enum_control import get_enum_values @@ -24,12 +24,12 @@ class MysqlDB: def __init__(self) -> None: self._pool = PooledDB( pymysql, - host=config.MYSQL_HOST, - port=config.MYSQL_PORT, - user=config.MYSQL_USER, - password=config.MYSQL_PASSWORD, - database=config.MYSQL_DATABASE, - charset=config.MYSQL_CHARSET, + host=httpfpt_config.MYSQL_HOST, + port=httpfpt_config.MYSQL_PORT, + user=httpfpt_config.MYSQL_USER, + password=httpfpt_config.MYSQL_PASSWORD, + database=httpfpt_config.MYSQL_DATABASE, + charset=httpfpt_config.MYSQL_CHARSET, maxconnections=15, blocking=True, # 连接池中如果没有可用连接后,是否阻塞等待 autocommit=False, # 是否自动提交 diff --git a/httpfpt/db/redis_db.py b/httpfpt/db/redis_db.py index e71fe63..7ccb63d 100644 --- a/httpfpt/db/redis_db.py +++ b/httpfpt/db/redis_db.py @@ -7,17 +7,17 @@ from redis import AuthenticationError, Redis from httpfpt.common.log import log -from httpfpt.core.get_conf import config +from httpfpt.core.get_conf import httpfpt_config class RedisDB(Redis): def __init__(self) -> None: super().__init__( - host=config.REDIS_HOST, - port=config.REDIS_PORT, - password=config.REDIS_PASSWORD, - db=config.REDIS_DATABASE, - socket_timeout=config.REDIS_TIMEOUT, + host=httpfpt_config.REDIS_HOST, + port=httpfpt_config.REDIS_PORT, + password=httpfpt_config.REDIS_PASSWORD, + db=httpfpt_config.REDIS_DATABASE, + socket_timeout=httpfpt_config.REDIS_TIMEOUT, decode_responses=True, # 转码 utf-8 ) self.prefix = 'httpfpt' diff --git a/httpfpt/run.py b/httpfpt/run.py index 8df2fef..e7d6a39 100644 --- a/httpfpt/run.py +++ b/httpfpt/run.py @@ -15,16 +15,8 @@ from httpfpt.common.log import log from httpfpt.common.yaml_handler import read_yaml -from httpfpt.core.get_conf import config -from httpfpt.core.path_conf import ( - ALLURE_ENV_FILE, - ALLURE_REPORT_ENV_FILE, - ALLURE_REPORT_HTML_PATH, - ALLURE_REPORT_PATH, - HTML_REPORT_PATH, - TEST_CASE_PATH, - YAML_REPORT_PATH, -) +from httpfpt.core.get_conf import httpfpt_config +from httpfpt.core.path_conf import httpfpt_path from httpfpt.db.redis_db import redis_client from httpfpt.utils.case_auto_generator import auto_generate_testcases from httpfpt.utils.request import case_data_parse as case_data @@ -57,7 +49,7 @@ def startup( run_args = [log_level] - default_case_path = os.sep.join([TEST_CASE_PATH, config.PROJECT_NAME]) + default_case_path = os.sep.join([httpfpt_path.testcase_dir, httpfpt_config.PROJECT_NAME]) if case_path: if '::' not in case_path: raise ValueError( @@ -76,14 +68,16 @@ def startup( run_path = default_case_path run_args.append(run_path) - html_report_filename = f'{config.PROJECT_NAME}_{get_current_time("%Y-%m-%d %H_%M_%S")}.html' + html_report_filename = f'{httpfpt_config.PROJECT_NAME}_{get_current_time("%Y-%m-%d %H_%M_%S")}.html' if html_report: - if not os.path.exists(HTML_REPORT_PATH): - os.makedirs(HTML_REPORT_PATH) - run_args.extend((f'--html={os.path.join(HTML_REPORT_PATH, html_report_filename)}', '--self-contained-html')) + if not os.path.exists(httpfpt_path.html_report_dir): + os.makedirs(httpfpt_path.html_report_dir) + run_args.extend( + (f'--html={os.path.join(httpfpt_path.html_report_dir, html_report_filename)}', '--self-contained-html') + ) if allure: - run_args.append(f'--alluredir={ALLURE_REPORT_PATH}') + run_args.append(f'--alluredir={httpfpt_path.allure_report_dir}') if allure_clear: run_args.append('--clean-alluredir') @@ -123,35 +117,39 @@ def startup( format_run_args.append(i) run_pytest_command_args = ' '.join(_ for _ in format_run_args) - log.info(f'开始运行项目:{config.PROJECT_NAME}' if run_path == default_case_path else f'开始运行:{run_path}') + log.info( + f'开始运行项目:{httpfpt_config.PROJECT_NAME}' if run_path == default_case_path else f'开始运行:{run_path}' + ) log.info(f'Pytest CLI: pytest {run_pytest_command_args}') log.info('🚀 START') pytest.main(run_args) log.info('🏁 FINISH') - yaml_report_files = os.listdir(YAML_REPORT_PATH) + yaml_report_files = os.listdir(httpfpt_path.yaml_report_dir) yaml_report_files.sort() - test_result = read_yaml(YAML_REPORT_PATH, filename=yaml_report_files[-1]) + test_result = read_yaml(httpfpt_path.yaml_report_dir, filename=yaml_report_files[-1]) - if html_report and config.EMAIL_SEND: + if html_report and httpfpt_config.EMAIL_SEND: SendEmail(test_result, html_report_filename).send_report() - if config.DINGDING_SEND: + if httpfpt_config.DINGDING_SEND: DingDing(test_result).send() - if config.FEISHU_SEND: + if httpfpt_config.FEISHU_SEND: FeiShu(test_result).send() - if config.WECHAT_SEND: + if httpfpt_config.WECHAT_SEND: WeChat(test_result).send() if allure: - if not os.path.exists(ALLURE_REPORT_ENV_FILE): - shutil.copyfile(ALLURE_ENV_FILE, ALLURE_REPORT_ENV_FILE) + if not os.path.exists(httpfpt_path.allure_report_env_file): + shutil.copyfile(httpfpt_path.allure_env_file, httpfpt_path.allure_report_env_file) if allure_serve: - subprocess.run(f'allure generate {ALLURE_REPORT_PATH} -o {ALLURE_REPORT_HTML_PATH} --clean') - subprocess.run(f'allure serve {ALLURE_REPORT_PATH}') + subprocess.run( + f'allure generate {httpfpt_path.allure_report_dir} -o {httpfpt_path.allure_html_report_dir} --clean' + ) + subprocess.run(f'allure serve {httpfpt_path.allure_report_dir}') def run( diff --git a/httpfpt/utils/auth_plugins.py b/httpfpt/utils/auth_plugins.py index de9ba70..26b340c 100644 --- a/httpfpt/utils/auth_plugins.py +++ b/httpfpt/utils/auth_plugins.py @@ -10,7 +10,7 @@ from httpfpt.common.errors import AuthError, SendRequestError from httpfpt.common.yaml_handler import read_yaml -from httpfpt.core.path_conf import AUTH_CONF_PATH +from httpfpt.core.path_conf import httpfpt_path from httpfpt.db.redis_db import redis_client from httpfpt.enums.request.auth import AuthType from httpfpt.utils.enum_control import get_enum_values @@ -27,7 +27,7 @@ def __init__(self) -> None: @lru_cache def get_auth_data(self) -> dict: """获取授权数据""" - auth_data = read_yaml(AUTH_CONF_PATH, filename='auth.yaml') + auth_data = read_yaml(httpfpt_path.auth_conf_dir, filename='auth.yaml') return auth_data def auth_type_verify(self) -> None: diff --git a/httpfpt/utils/case_auto_generator.py b/httpfpt/utils/case_auto_generator.py index c3ad60c..f74d2bd 100644 --- a/httpfpt/utils/case_auto_generator.py +++ b/httpfpt/utils/case_auto_generator.py @@ -4,8 +4,8 @@ from pathlib import Path -from httpfpt.core.get_conf import config -from httpfpt.core.path_conf import TEST_CASE_PATH +from httpfpt.core.get_conf import httpfpt_config +from httpfpt.core.path_conf import httpfpt_path from httpfpt.utils.file_control import get_file_property, search_all_case_data_files, search_all_testcase_files from httpfpt.utils.rich_console import console @@ -88,12 +88,16 @@ def {testcase_func_name}(self, data): send_request.send_request(data) ''' # 创建测试用例文件 - tag = case_filename.split(config.PROJECT_NAME)[1].split(os.path.sep)[1:-1] + tag = case_filename.split(httpfpt_config.PROJECT_NAME)[1].split(os.path.sep)[1:-1] new_testcase_filename = testcase_func_name + '.py' if tag: - case_path = os.path.join(TEST_CASE_PATH, config.PROJECT_NAME, *tag, new_testcase_filename) + case_path = os.path.join( + httpfpt_path.testcase_dir, httpfpt_config.PROJECT_NAME, *tag, new_testcase_filename + ) else: - case_path = os.path.join(TEST_CASE_PATH, config.PROJECT_NAME, new_testcase_filename) + case_path = os.path.join( + httpfpt_path.testcase_dir, httpfpt_config.PROJECT_NAME, new_testcase_filename + ) new_testcase_dir = Path(case_path).parent if not new_testcase_dir.exists(): new_testcase_dir.mkdir(parents=True, exist_ok=True) diff --git a/httpfpt/utils/cli/about_testcase.py b/httpfpt/utils/cli/about_testcase.py index a1f752d..df44e6f 100644 --- a/httpfpt/utils/cli/about_testcase.py +++ b/httpfpt/utils/cli/about_testcase.py @@ -9,8 +9,8 @@ from httpfpt.common.json_handler import read_json_file from httpfpt.common.yaml_handler import read_yaml -from httpfpt.core.get_conf import config -from httpfpt.core.path_conf import CASE_DATA_PATH +from httpfpt.core.get_conf import httpfpt_config +from httpfpt.core.path_conf import httpfpt_path from httpfpt.enums.case_data_type import CaseDataType from httpfpt.schemas.case_data import CaseData from httpfpt.utils.case_auto_generator import auto_generate_testcases @@ -37,7 +37,7 @@ def testcase_data_verify(verify: str) -> None: console.print(f'🔥 开始验证 {verify} 测试数据结构...') file_type = get_file_property(verify)[2] if os.path.isfile(verify): - data_path = os.path.join(CASE_DATA_PATH, config.PROJECT_NAME) + data_path = os.path.join(httpfpt_path.case_data_dir, httpfpt_config.PROJECT_NAME) if file_type == CaseDataType.JSON: file_data = read_json_file(str(data_path), verify) else: diff --git a/httpfpt/utils/data_manage/apifox.py b/httpfpt/utils/data_manage/apifox.py index 1ed5f3a..71a504a 100644 --- a/httpfpt/utils/data_manage/apifox.py +++ b/httpfpt/utils/data_manage/apifox.py @@ -7,8 +7,8 @@ from httpfpt.common.json_handler import read_json_file from httpfpt.common.yaml_handler import write_yaml -from httpfpt.core.get_conf import config -from httpfpt.core.path_conf import CASE_DATA_PATH +from httpfpt.core.get_conf import httpfpt_config +from httpfpt.core.path_conf import httpfpt_path from httpfpt.utils.data_manage.base_format import format_value from httpfpt.utils.file_control import get_file_property from httpfpt.utils.rich_console import console @@ -63,8 +63,10 @@ def import_apifox_to_yaml(self, source: str, project: str | None = None) -> None case_config['allure']['feature'] = case_config['module'] = k case_file_data = {'config': case_config, 'test_steps': v} write_yaml( - CASE_DATA_PATH, - os.sep.join([project or config.PROJECT_NAME, k, get_file_property(source)[1] + '.yaml']), + httpfpt_path.case_data_dir, + os.sep.join( + [project or httpfpt_config.PROJECT_NAME, k, get_file_property(source)[1] + '.yaml'] + ), case_file_data, mode='w', ) @@ -73,8 +75,8 @@ def import_apifox_to_yaml(self, source: str, project: str | None = None) -> None for v in root_case.values(): case_file_data = {'config': case_config, 'test_steps': v} write_yaml( - CASE_DATA_PATH, - os.sep.join([project or config.PROJECT_NAME, get_file_property(source)[1] + '.yaml']), + httpfpt_path.case_data_dir, + os.sep.join([project or httpfpt_config.PROJECT_NAME, get_file_property(source)[1] + '.yaml']), case_file_data, mode='w', ) diff --git a/httpfpt/utils/data_manage/openapi.py b/httpfpt/utils/data_manage/openapi.py index a7a9bfb..1303635 100644 --- a/httpfpt/utils/data_manage/openapi.py +++ b/httpfpt/utils/data_manage/openapi.py @@ -12,8 +12,8 @@ from httpfpt.common.json_handler import read_json_file from httpfpt.common.yaml_handler import write_yaml -from httpfpt.core.get_conf import config -from httpfpt.core.path_conf import CASE_DATA_PATH +from httpfpt.core.get_conf import httpfpt_config +from httpfpt.core.path_conf import httpfpt_path from httpfpt.utils.data_manage.base_format import format_value from httpfpt.utils.file_control import get_file_property from httpfpt.utils.rich_console import console @@ -138,7 +138,7 @@ def import_openapi_to_yaml(self, openapi_source: str, project: str | None = None for k, v in tag_case.items(): tag_filename = os.sep.join( [ - project or config.PROJECT_NAME, + project or httpfpt_config.PROJECT_NAME, k, get_file_property(openapi_source)[1] + '.yaml' if not openapi_source.startswith('http') @@ -151,7 +151,7 @@ def import_openapi_to_yaml(self, openapi_source: str, project: str | None = None if k == 'root': root_filename = os.sep.join( [ - project or config.PROJECT_NAME, + project or httpfpt_config.PROJECT_NAME, get_file_property(openapi_source)[1] + '.yaml' if not openapi_source.startswith('http') else f'openapi_{get_current_timestamp()}.yaml', @@ -160,7 +160,7 @@ def import_openapi_to_yaml(self, openapi_source: str, project: str | None = None else: root_filename = os.sep.join( [ - project or config.PROJECT_NAME, + project or httpfpt_config.PROJECT_NAME, get_file_property(openapi_source)[1] + '.yaml' if not openapi_source.startswith('http') else f'openapi_{k}.yaml', @@ -183,10 +183,10 @@ def import_openapi_to_yaml(self, openapi_source: str, project: str | None = None case_config['allure']['feature'] = case_config['module'] = k case_file_data = {'config': case_config, 'test_steps': v} write_yaml( - CASE_DATA_PATH, + httpfpt_path.case_data_dir, os.sep.join( [ - project or config.PROJECT_NAME, + project or httpfpt_config.PROJECT_NAME, k, get_file_property(openapi_source)[1] + '.yaml' if not openapi_source.startswith('http') @@ -213,8 +213,8 @@ def import_openapi_to_yaml(self, openapi_source: str, project: str | None = None ) case_file_data = {'config': case_config, 'test_steps': v} write_yaml( - CASE_DATA_PATH, - os.sep.join([project or config.PROJECT_NAME, filename]), + httpfpt_path.case_data_dir, + os.sep.join([project or httpfpt_config.PROJECT_NAME, filename]), case_file_data, mode='w', ) @@ -230,7 +230,7 @@ def import_openapi_to_yaml(self, openapi_source: str, project: str | None = None case_file_data = {'config': case_config, 'test_steps': v} tag_filename = os.sep.join( [ - project or config.PROJECT_NAME, + project or httpfpt_config.PROJECT_NAME, k, get_file_property(openapi_source)[1] + '.yaml' if not openapi_source.startswith('http') @@ -239,7 +239,7 @@ def import_openapi_to_yaml(self, openapi_source: str, project: str | None = None ) is_write = Confirm.ask(f'❓ 是否需要创建 {tag_filename} 数据文件?', default=True) if is_write: - write_yaml(CASE_DATA_PATH, tag_filename, case_file_data, mode='w') + write_yaml(httpfpt_path.case_data_dir, tag_filename, case_file_data, mode='w') # 写入项目根目录 if len(root_case) > 0: for k, v in root_case.items(): @@ -259,8 +259,8 @@ def import_openapi_to_yaml(self, openapi_source: str, project: str | None = None if is_write: case_file_data = {'config': case_config, 'test_steps': v} write_yaml( - CASE_DATA_PATH, - os.sep.join([project or config.PROJECT_NAME, root_filename]), + httpfpt_path.case_data_dir, + os.sep.join([project or httpfpt_config.PROJECT_NAME, root_filename]), case_file_data, mode='w', ) diff --git a/httpfpt/utils/file_control.py b/httpfpt/utils/file_control.py index e0f2312..bcc3946 100644 --- a/httpfpt/utils/file_control.py +++ b/httpfpt/utils/file_control.py @@ -7,8 +7,8 @@ from pathlib import Path -from httpfpt.core.get_conf import config -from httpfpt.core.path_conf import CASE_DATA_PATH, TEST_CASE_PATH +from httpfpt.core.get_conf import httpfpt_config +from httpfpt.core.path_conf import httpfpt_path def get_file_property(filepath: str) -> tuple[str, str, str]: @@ -31,7 +31,9 @@ def search_all_case_data_files(filepath: str | None = None) -> list: :return: """ - case_data_filepath = os.path.join(CASE_DATA_PATH, f'{config.PROJECT_NAME}') if filepath is None else filepath + case_data_filepath = ( + os.path.join(httpfpt_path.case_data_dir, f'{httpfpt_config.PROJECT_NAME}') if filepath is None else filepath + ) files = ( glob.glob(os.path.join(case_data_filepath, '**', '*.yaml'), recursive=True) + glob.glob(os.path.join(case_data_filepath, '**', '*.yml'), recursive=True) @@ -46,7 +48,9 @@ def search_all_testcase_files() -> list: :return: """ - files = glob.glob(os.path.join(TEST_CASE_PATH, f'{config.PROJECT_NAME}', '**', 'test_*.py'), recursive=True) + files = glob.glob( + os.path.join(httpfpt_path.testcase_dir, f'{httpfpt_config.PROJECT_NAME}', '**', 'test_*.py'), recursive=True + ) return files diff --git a/httpfpt/utils/relate_testcase_executor.py b/httpfpt/utils/relate_testcase_executor.py index a1347b0..eddd51f 100644 --- a/httpfpt/utils/relate_testcase_executor.py +++ b/httpfpt/utils/relate_testcase_executor.py @@ -88,15 +88,11 @@ def exec_setup_testcase(parsed_data: dict, setup_testcase: str | dict) -> dict | case_data.update(testcase_data) response = relate_testcase_exec_with_new_request_data(case_data) if setup_testcase.get('response') is not None: - testcase_data = { - 'set_var_response': setup_testcase['response'], - } + testcase_data = {'set_var_response': setup_testcase['response']} relate_testcase_extract_with_response(testcase_data, response) else: if setup_testcase.get('response') is not None: - testcase_data = { - 'set_var_response': setup_testcase['response'], - } + testcase_data = {'set_var_response': setup_testcase['response']} case_data.update(testcase_data) relate_testcase_extract(case_data) diff --git a/httpfpt/utils/request/request_data_parse.py b/httpfpt/utils/request/request_data_parse.py index c1ac7a6..4fd86d0 100644 --- a/httpfpt/utils/request/request_data_parse.py +++ b/httpfpt/utils/request/request_data_parse.py @@ -15,7 +15,7 @@ from httpfpt.common.env_handler import get_env_dict from httpfpt.common.errors import RequestDataParseError from httpfpt.common.log import log -from httpfpt.core.path_conf import RUN_ENV_PATH +from httpfpt.core.path_conf import httpfpt_path from httpfpt.db.mysql_db import mysql_client from httpfpt.enums.allure_severity_type import SeverityType from httpfpt.enums.request.auth import AuthType @@ -334,7 +334,7 @@ def url(self) -> str: if not url.startswith('http'): _env = self.env try: - env_file = os.path.join(RUN_ENV_PATH, _env) + env_file = os.path.join(httpfpt_path.run_env_dir, _env) env_dict = get_env_dict(env_file) except Exception as e: raise RequestDataParseError(f'环境变量 {_env} 读取失败: {e}') diff --git a/httpfpt/utils/request/vars_extractor.py b/httpfpt/utils/request/vars_extractor.py index 0de35ea..9c82e08 100644 --- a/httpfpt/utils/request/vars_extractor.py +++ b/httpfpt/utils/request/vars_extractor.py @@ -11,7 +11,7 @@ from httpfpt.common.log import log from httpfpt.common.variable_cache import variable_cache from httpfpt.common.yaml_handler import read_yaml -from httpfpt.core.path_conf import RUN_ENV_PATH, TEST_DATA_PATH +from httpfpt.core.path_conf import httpfpt_path from httpfpt.utils.request.vars_recorder import record_variables @@ -45,7 +45,7 @@ def vars_replace(self, target: dict, env: str | None = None, exception: bool = T if not _env or not isinstance(_env, str): raise RequestDataParseError('运行环境获取失败, 测试用例数据缺少 config:request:env 参数') try: - env_file = os.path.join(RUN_ENV_PATH, _env) + env_file = os.path.join(httpfpt_path.run_env_dir, _env) env_vars = get_env_dict(env_file) except OSError: raise RequestDataParseError('运行环境获取失败, 请检查测试用例环境配置') @@ -61,7 +61,7 @@ def vars_replace(self, target: dict, env: str | None = None, exception: bool = T # 替换: 临时变量 > 环境变量 > 全局变量 cache_value = variable_cache.get(var_key, default=default) if cache_value == default: - global_vars = read_yaml(TEST_DATA_PATH, filename='global_vars.yaml') + global_vars = read_yaml(httpfpt_path.data_dir, filename='global_vars.yaml') var_value = env_vars.get(var_key.upper(), global_vars.get(var_key, default)) if var_value != default: str_target = var_re.sub(str(var_value), str_target, 1) diff --git a/httpfpt/utils/request/vars_recorder.py b/httpfpt/utils/request/vars_recorder.py index 2ea5ae1..4937720 100644 --- a/httpfpt/utils/request/vars_recorder.py +++ b/httpfpt/utils/request/vars_recorder.py @@ -6,7 +6,7 @@ from httpfpt.common.errors import JsonPathFindError, VariableError from httpfpt.common.variable_cache import variable_cache from httpfpt.common.yaml_handler import write_yaml_vars -from httpfpt.core.path_conf import RUN_ENV_PATH +from httpfpt.core.path_conf import httpfpt_path from httpfpt.enums.var_type import VarType @@ -28,7 +28,7 @@ def record_variables(jsonpath: str, target: dict, key: str, set_type: str, env: if set_type == VarType.CACHE: variable_cache.set(key, value_str) elif set_type == VarType.ENV: - write_env_vars(RUN_ENV_PATH, env, key, value_str) + write_env_vars(httpfpt_path.run_env_dir, env, key, value_str) elif set_type == VarType.GLOBAL: write_yaml_vars({key: value_str}) else: diff --git a/httpfpt/utils/send_report/dingding.py b/httpfpt/utils/send_report/dingding.py index 9685071..ee91514 100644 --- a/httpfpt/utils/send_report/dingding.py +++ b/httpfpt/utils/send_report/dingding.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- from httpfpt.common.log import log -from httpfpt.core.get_conf import config +from httpfpt.core.get_conf import httpfpt_config class DingDing: @@ -16,9 +16,9 @@ def send(self) -> None: data = { 'msgtype': 'markdown', 'markdown': { - 'title': config.TEST_REPORT_TITLE, - 'text': f"> ## {config.PROJECT_NAME} 自动化测试报告\n\n" - f"> 👤 测试人员: {config.TESTER_NAME}\n\n" + 'title': httpfpt_config.TEST_REPORT_TITLE, + 'text': f"> ## {httpfpt_config.PROJECT_NAME} 自动化测试报告\n\n" + f"> 👤 测试人员: {httpfpt_config.TESTER_NAME}\n\n" f"> 🤖 测试结果: {self.content['result']}\n\n" f"> ✅ 通过用例: {self.content['passed']}\n\n" f"> 🔧 失败用例: {self.content['failed']}\n\n" @@ -30,10 +30,10 @@ def send(self) -> None: }, } response = requests.session().post( - url=config.DINGDING_WEBHOOK, + url=httpfpt_config.DINGDING_WEBHOOK, json=data, headers=headers, - proxies=config.DINGDING_PROXY, # type: ignore + proxies=httpfpt_config.DINGDING_PROXY, # type: ignore ) response.raise_for_status() except Exception as e: diff --git a/httpfpt/utils/send_report/email.py b/httpfpt/utils/send_report/email.py index 7b155aa..6331d9a 100644 --- a/httpfpt/utils/send_report/email.py +++ b/httpfpt/utils/send_report/email.py @@ -13,8 +13,8 @@ from jinja2 import Template from httpfpt.common.log import log -from httpfpt.core.get_conf import config -from httpfpt.core.path_conf import HTML_EMAIL_REPORT_PATH +from httpfpt.core.get_conf import httpfpt_config +from httpfpt.core.path_conf import httpfpt_path from httpfpt.enums.email_type import EmailType from httpfpt.utils.file_control import get_file_property @@ -29,14 +29,14 @@ def take_report(self) -> MIMEMultipart: 获取报告 """ msg = MIMEMultipart() - msg['Subject'] = config.TEST_REPORT_TITLE - msg['From'] = config.EMAIL_USER + msg['Subject'] = httpfpt_config.TEST_REPORT_TITLE + msg['From'] = httpfpt_config.EMAIL_USER msg['date'] = time.strftime('%a, %d %b %Y %H:%M:%S %z') - self.content.update({'test_title': config.TEST_REPORT_TITLE}) - self.content.update({'tester_name': config.TESTER_NAME}) + self.content.update({'test_title': httpfpt_config.TEST_REPORT_TITLE}) + self.content.update({'tester_name': httpfpt_config.TESTER_NAME}) # 邮件正文 - with open(os.path.join(HTML_EMAIL_REPORT_PATH, 'email_report.html'), 'r', encoding='utf-8') as f: + with open(os.path.join(httpfpt_path.html_email_report_dir, 'email_report.html'), 'r', encoding='utf-8') as f: html = Template(f.read()) mail_body = MIMEText(html.render(**self.content), _subtype='html', _charset='utf-8') @@ -60,11 +60,13 @@ def take_error(self) -> MIMEMultipart: """ msg = MIMEMultipart() msg['Subject'] = 'HttpFpt 运行异常通知' - msg['From'] = config.EMAIL_USER + msg['From'] = httpfpt_config.EMAIL_USER msg['date'] = time.strftime('%a, %d %b %Y %H:%M:%S %z') # 邮件正文 - with open(os.path.join(HTML_EMAIL_REPORT_PATH, 'email_notification.html'), 'r', encoding='utf-8') as f: + with open( + os.path.join(httpfpt_path.html_email_report_dir, 'email_notification.html'), 'r', encoding='utf-8' + ) as f: html = Template(f.read()) mail_body = MIMEText(html.render(**self.content), _subtype='html', _charset='utf-8') @@ -81,12 +83,12 @@ def _send(self, msg_type: int) -> None: msg = self.take_report().as_string() elif msg_type == EmailType.ERROR: msg = self.take_error().as_string() - if config.EMAIL_SSL: - smtp = smtplib.SMTP_SSL(host=config.EMAIL_SERVER, port=config.EMAIL_PORT) + if httpfpt_config.EMAIL_SSL: + smtp = smtplib.SMTP_SSL(host=httpfpt_config.EMAIL_SERVER, port=httpfpt_config.EMAIL_PORT) else: - smtp = smtplib.SMTP(host=config.EMAIL_SERVER, port=config.EMAIL_PORT) - smtp.login(config.EMAIL_USER, config.EMAIL_PASSWORD) - smtp.sendmail(config.EMAIL_USER, config.EMAIL_SEND_TO, msg) + smtp = smtplib.SMTP(host=httpfpt_config.EMAIL_SERVER, port=httpfpt_config.EMAIL_PORT) + smtp.login(httpfpt_config.EMAIL_USER, httpfpt_config.EMAIL_PASSWORD) + smtp.sendmail(httpfpt_config.EMAIL_USER, httpfpt_config.EMAIL_SEND_TO, msg) smtp.quit() def send_report(self) -> None: diff --git a/httpfpt/utils/send_report/feishu.py b/httpfpt/utils/send_report/feishu.py index de021e6..df7e947 100644 --- a/httpfpt/utils/send_report/feishu.py +++ b/httpfpt/utils/send_report/feishu.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- from httpfpt.common.log import log -from httpfpt.core.get_conf import config +from httpfpt.core.get_conf import httpfpt_config class FeiShu: @@ -19,9 +19,9 @@ def send(self) -> None: 'content': { 'post': { 'zh_cn': { - 'title': config.TEST_REPORT_TITLE, + 'title': httpfpt_config.TEST_REPORT_TITLE, 'content': [ - [{'tag': 'text', 'text': f'👤 测试人员: {config.TESTER_NAME}'}], + [{'tag': 'text', 'text': f'👤 测试人员: {httpfpt_config.TESTER_NAME}'}], [{'tag': 'text', 'text': f"🤖 测试结果: {self.content['result']}"}], [{'tag': 'text', 'text': f"✅ 通过用例: {self.content['passed']}"}], [{'tag': 'text', 'text': f"🔧 失败用例: {self.content['failed']}"}], @@ -36,10 +36,10 @@ def send(self) -> None: }, } response = requests.session().post( - url=config.FEISHU_WEBHOOK, + url=httpfpt_config.FEISHU_WEBHOOK, json=data, headers=headers, - proxies=config.FEISHU_PROXY, # type: ignore + proxies=httpfpt_config.FEISHU_PROXY, # type: ignore ) response.raise_for_status() except Exception as e: diff --git a/httpfpt/utils/send_report/wechat.py b/httpfpt/utils/send_report/wechat.py index 50af58a..8b0e230 100644 --- a/httpfpt/utils/send_report/wechat.py +++ b/httpfpt/utils/send_report/wechat.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- from httpfpt.common.log import log -from httpfpt.core.get_conf import config +from httpfpt.core.get_conf import httpfpt_config class WeChat: @@ -18,8 +18,8 @@ def send(self) -> None: data = { 'msgtype': 'markdown', 'markdown': { - 'content': f"# {config.TEST_REPORT_TITLE}\n" - f"> 👤 测试人员: **{config.TESTER_NAME}**\n" + 'content': f"# {httpfpt_config.TEST_REPORT_TITLE}\n" + f"> 👤 测试人员: **{httpfpt_config.TESTER_NAME}**\n" f"> 🤖 测试结果: **{self.content['result']}**\n" f"> ✅ 通过用例: **{self.content['passed']}**\n" f"> 🔧 失败用例: **{self.content['failed']}**\n" @@ -31,10 +31,10 @@ def send(self) -> None: }, } response = requests.session().post( - url=config.WECHAT_WEBHOOK, + url=httpfpt_config.WECHAT_WEBHOOK, json=data, headers=headers, - proxies=config.WECHAT_PROXY, # type: ignore + proxies=httpfpt_config.WECHAT_PROXY, # type: ignore ) response.raise_for_status() except Exception as e: diff --git a/pdm.lock b/pdm.lock index 20d58cf..96b8f4a 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "test"] strategy = ["cross_platform"] lock_version = "4.4.1" -content_hash = "sha256:7d4e7a7ac3a09a1bde5bc9d99002f31173e2562c86ce2109153ad5f09f23f46a" +content_hash = "sha256:9e18448e0802c41a0bf0beb546bb530e34caaf4bb099be2a87dc2c2f5e947a07" [[package]] name = "allure-pytest" diff --git a/pyproject.toml b/pyproject.toml index 596178d..adbf99b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ dependencies = [ "xlrd==1.2.0", "eval-type-backport>=0.1.3", "stamina==24.1.0", - "typing-extensions>=4.8.0", + "typing_extensions>=4.8.0", "jsonschema>=4.21.1", "pygments>=2.17.2", "glom>=23.5.0", @@ -54,6 +54,9 @@ test = [ "ruff>=0.3.0", ] +[tool.pdm.scripts] +lint = "pre-commit run --all-files" + [build-system] requires = ["pdm-backend"] build-backend = "pdm.backend"