Files
37duAutomation/tests/run_all_tests.py
T
puddy 8c97d48382 refactor: 重构项目代码结构与依赖管理
1.  **依赖与导入路径修正
    - 移除所有本地sys.path插入,统一使用绝对包导入
    - 修复logger导入路径,统一从app.utils导入
    - 重构intelligent_retry.py移除冗余导入
    - 统一hrbp各模块的导入路径

2.  **项目配置与构建
    - 新增pyproject.toml配置文件,规范项目元数据与依赖声明
    - 更新requirements.txt新增pyautogui、pywin32、pyperclip依赖

3.  **业务模块重构
    - 重构请假/加班审批模块的导入路径与内部逻辑
    - 重命名审批结果描述(将"不通过"改为"驳回")
    - 统一代码中的箭头符号(将→改为->)
    - 新增请假表单解析模块、钉钉通知模块
    - 重构加班/请假校验模块的报告生成逻辑,统一报告格式与推送流程

4.  **测试与文档
    - 新增端到端测试脚本与统一测试运行器
    - 完善README.md文档,补充项目结构、功能说明与使用方法
    - 新增钉钉消息推送工具文档
    - 新增测试用例与辅助工具

5.  **其他优化
    - 修复common/parser.py中的正则表达式兼容单引号的HTML属性
    - 新增session_manager.py移除冗余导入与路径修正
    - 新增OA审批报告生成逻辑优化,支持分组统计与详细清单输出
2026-08-07 00:18:49 +08:00

132 lines
4.2 KiB
Python

# -*- coding: utf-8 -*-
"""
@Module: tests.run_all_tests
@FileName: run_all_tests.py
@Author: 小布丁
@CreateTime: 2026-08-06
@Description: 统一测试运行器
用法:
python tests/run_all_tests.py # 仅运行离线测试
python tests/run_all_tests.py --online # 运行全部测试(含在线)
python tests/run_all_tests.py --list # 列出所有测试
python tests/run_all_tests.py test_05 # 运行指定测试
"""
import argparse
import os
import subprocess
import sys
# 测试文件列表(按依赖顺序排列)
ALL_TESTS = [
# 离线测试(无需登录,可独立运行)
("test_04_parsers", "离线", "解析函数(排班/打卡/加班表单)"),
("test_05_leave_validator", "离线", "请假校验模块"),
# 在线测试(需登录态,有依赖顺序)
("test_01_login_session", "在线", "登录 + 会话 + 待办列表"),
("test_02_form_detail", "在线", "SSO + WfActivity + WorkformEngine"),
("test_03_attendance", "在线", "排班 + 打卡明细接口"),
("test_06_leave_online", "在线", "请假记录 + 全流程"),
]
# 在线测试需要在离线测试之后运行
ONLINE_TESTS = [t for t in ALL_TESTS if t[1] == "在线"]
OFFLINE_TESTS = [t for t in ALL_TESTS if t[1] == "离线"]
def print_header(text: str):
"""打印分隔标题"""
width = 60
print(f"\n{'=' * width}")
print(f" {text}")
print(f"{'=' * width}")
def run_test(test_name: str) -> bool:
"""运行单个测试文件,返回是否成功"""
test_file = os.path.join(os.path.dirname(__file__), "hrbp", f"{test_name}.py")
if not os.path.exists(test_file):
print(f" [错误] 测试文件不存在: {test_file}")
return False
print(f"\n ▶ 运行: {test_name}")
result = subprocess.run(
[sys.executable, test_file],
capture_output=False,
cwd=os.path.join(os.path.dirname(__file__), ".."),
)
return result.returncode == 0
def list_tests():
"""列出所有测试"""
print_header("可用测试列表")
for name, kind, desc in ALL_TESTS:
print(f" [{kind}] {name:30s} {desc}")
print(f"\n 离线测试: {len(OFFLINE_TESTS)} 个")
print(f" 在线测试: {len(ONLINE_TESTS)} 个")
print(f" 共计: {len(ALL_TESTS)} 个")
def run_selected(name: str) -> bool:
"""运行指定测试(支持模糊匹配)"""
matched = [t for t in ALL_TESTS if name in t[0]]
if not matched:
print(f"未找到匹配 '{name}' 的测试")
return False
success = True
for test_name, kind, desc in matched:
print_header(f"运行: {test_name} ({kind} - {desc})")
if not run_test(test_name):
success = False
return success
def main():
parser = argparse.ArgumentParser(description="Process-Automation 统一测试运行器")
parser.add_argument("--online", action="store_true", help="同时运行在线测试(需登录态)")
parser.add_argument("--list", action="store_true", help="列出所有测试")
parser.add_argument("test", nargs="?", help="运行指定测试(支持模糊匹配)")
args = parser.parse_args()
if args.list:
list_tests()
return
if args.test:
run_selected(args.test)
return
# 默认:运行所有离线测试
all_pass = True
print_header("Process-Automation 测试套件")
print(f" 离线测试: {len(OFFLINE_TESTS)} 个")
if args.online:
print(f" 在线测试: {len(ONLINE_TESTS)} 个")
print()
for test_name, kind, desc in OFFLINE_TESTS:
print(f"\n [{kind}] {desc}")
if not run_test(test_name):
all_pass = False
if args.online:
print(f"\n{'─' * 60}")
print(" 开始在线测试...")
for test_name, kind, desc in ONLINE_TESTS:
print(f"\n [{kind}] {desc}")
if not run_test(test_name):
all_pass = False
print_header("测试结果汇总")
if all_pass:
print(" ✅ 全部通过")
else:
print(" ❌ 存在失败项")
print(f"{'=' * 60}")
if __name__ == "__main__":
main()