From ffbde1158bbacd0c69c553e75e75caca4aa00427 Mon Sep 17 00:00:00 2001 From: CNWei Date: Wed, 19 Mar 2025 16:53:21 +0800 Subject: [PATCH] =?UTF-8?q?feat,fix():=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优化 settings(使用环境变量) - 修复bug --- .gitignore | 3 ++- commons/settings.py | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 29eada9..ef15b4d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ poetry.lock .pytest_cache/ report/ temp/ -logs/ \ No newline at end of file +logs/ +.env \ No newline at end of file diff --git a/commons/settings.py b/commons/settings.py index 5b285d7..2e594c4 100644 --- a/commons/settings.py +++ b/commons/settings.py @@ -10,19 +10,23 @@ @desc: """ from pathlib import Path +import os +from dotenv import load_dotenv + +load_dotenv() root_path = (Path(__file__)).resolve().parents[1] -base_url = 'http://119.91.19.171:40065' +base_url = os.getenv("BASE_URL") cases_dir = rf"{root_path}\TestCases\answer" exchanger = rf"{root_path}\extract.yaml" id_path = rf"{root_path}\id.yaml" -db_host = '119.91.19.171' # ip -db_port = 3306 # 端口 -db_user = 'root' # 用户名 -db_password = 'mysql_hNahSe' # 密码 -db_database = 'answer' # 库名 +db_host = os.getenv("DB_HOST") # ip +db_port = os.getenv("DB_PORT") # 端口 +db_user = os.getenv("DB_USER") # 用户名 +db_password = os.getenv("DB_PASSWORD") # 密码 +db_database = os.getenv("DB_DATABASE") # 库名 allure_epic: str = "项目名称:answer" allure_feature: str = "默认特征(feature)" @@ -33,4 +37,5 @@ rsa_private = "" if __name__ == '__main__': - print(root_path) \ No newline at end of file + print(root_path) + print(base_url,db_host,db_port,db_user,db_password,db_database) \ No newline at end of file