#!/usr/bin/env python3 """ 测试运行脚本 """ import subprocess import sys import os def run_tests(): """运行所有测试""" print("🧪 开始运行AI Talk回调接口测试...") # 设置环境变量为测试模式 os.environ["TESTING"] = "1" try: # 运行pytest result = subprocess.run([ sys.executable, "-m", "pytest", "test_callback.py", "-v", "--tb=short", "--color=yes" ], capture_output=True, text=True) print(result.stdout) if result.stderr: print("错误信息:") print(result.stderr) if result.returncode == 0: print("✅ 所有测试通过!") return True else: print("❌ 测试失败!") return False except Exception as e: print(f"❌ 运行测试时出错: {e}") return False def run_specific_test(test_name: str): """运行特定测试""" print(f"🧪 运行特定测试: {test_name}") os.environ["TESTING"] = "1" try: result = subprocess.run([ sys.executable, "-m", "pytest", "test_callback.py", f"-k={test_name}", "-v", "--tb=short", "--color=yes" ], capture_output=True, text=True) print(result.stdout) if result.stderr: print("错误信息:") print(result.stderr) return result.returncode == 0 except Exception as e: print(f"❌ 运行测试时出错: {e}") return False if __name__ == "__main__": if len(sys.argv) > 1: # 运行特定测试 test_name = sys.argv[1] run_specific_test(test_name) else: # 运行所有测试 run_tests()