提交 1a1226b7 authored 作者: 陈泽健's avatar 陈泽健

refactor(测试用例):优化测试用例中导入 Base模块的方式

- 修改了获取 Base 目录路径的方法,确保正确添加到 sys.path
- 使用 try-except 结构处理可能的 ModuleNotFoundError 异常
-优化代码结构,提高可读性和健壮性
上级 4f0658f8
...@@ -21,7 +21,7 @@ logging.basicConfig( ...@@ -21,7 +21,7 @@ logging.basicConfig(
# 全局配置 # 全局配置
message_queue = Queue() message_queue = Queue()
THREAD_COUNT = 20 # 减少线程数量便于观察进度 THREAD_COUNT = 110 # 减少线程数量便于观察进度
DOWNLOAD_DIR = "downloads" DOWNLOAD_DIR = "downloads"
os.makedirs(DOWNLOAD_DIR, exist_ok=True) os.makedirs(DOWNLOAD_DIR, exist_ok=True)
...@@ -139,8 +139,10 @@ def worker_thread(): ...@@ -139,8 +139,10 @@ def worker_thread():
actual_auth = payload["headers"]["Authorization"] actual_auth = payload["headers"]["Authorization"]
udid = payload["udid"][0] udid = payload["udid"][0]
# 构建请求参数 # 构建apk的请求参数
url = "http://192.168.5.229:8999/androidPanel/pack/download?id=30" # url = "http://192.168.5.229:8999/androidPanel/pack/download?id=30"
# 构建pak的请求参数
url = "http://192.168.5.229:8999/androidPanel/pack/download?id=29"
headers = { headers = {
"Content-Type": "application/x-www-form-urlencoded", "Content-Type": "application/x-www-form-urlencoded",
......
import sys import sys
import os import os
from hytest import *
# 获取当前脚本的绝对路径 # 获取 Base 目录的绝对路径,并加入 sys.path
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径 base_dir = os.path.abspath(os.path.join(current_dir, '..', '..', '..', 'Base'))
预定系统_path = os.path.abspath(os.path.join(current_dir, '..','..')) if base_dir not in sys.path:
# 添加路径 print(f"Adding Base directory to sys.path: {base_dir}")
sys.path.append(预定系统_path) sys.path.insert(0, base_dir)
# 导入模块
from 预定系统.Base.base import * try:
from base import *
except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}")
def suite_setup(): def suite_setup():
STEP(1, "初始化浏览器") STEP(1, "初始化浏览器")
......
import sys import sys
import os import os
from hytest import *
# 获取当前脚本的绝对路径 # 获取 Base 目录的绝对路径,并加入 sys.path
current_dir = os.path.dirname(os.path.abspath(__file__)) current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建预定系统的绝对路径 (修改路径构建方式) base_dir = os.path.abspath(os.path.join(current_dir, '..', '..', '..', 'Base'))
预定系统_path = os.path.abspath(os.path.join(current_dir, '..', '..', '..')) if base_dir not in sys.path:
# 添加路径 print(f"Adding Base directory to sys.path: {base_dir}")
sys.path.append(预定系统_path) sys.path.insert(0, base_dir)
# 导入模块
from 预定系统.Base.base import *
try:
from base import *
except ModuleNotFoundError as e:
print(f"ModuleNotFoundError: {e}")
# 获取当前脚本所在的目录
current_dir = os.path.dirname(os.path.abspath(__file__))
# 构建XLSX文件的绝对路径
xlsx_file_path = os.path.join(current_dir, '..', '..', '..', '测试数据', '会议预定测试用例.xlsx')
# 构建XLSX文件的绝对路径 (修正路径) # 构建XLSX文件的绝对路径 (修正路径)
xlsx_file_path = os.path.join(预定系统_path, '测试数据', '会议预定测试用例.xlsx') # xlsx_file_path = os.path.join(预定系统_path, '测试数据', '会议预定测试用例.xlsx')
class LicensePlateFilling: class LicensePlateFilling:
tags = ['工商银行项目测试'] tags = ['工商银行项目测试']
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论