Files
Haocode/tests/run_tests.py
T
2026-09-17 16:30:02 +08:00

34 lines
989 B
Python

"""离线测试 harness(无 pytest 依赖):
运行: conda run -n haocode python tests/run_tests.py
"""
import importlib.util
import os
import sys
import traceback
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
spec = importlib.util.spec_from_file_location(
"test_agent_core", os.path.join(os.path.dirname(__file__), "test_agent_core.py"))
mod = importlib.util.module_from_spec(spec)
# 替换 pytest 依赖后加载
import types
_py_stub = types.ModuleType("pytest")
sys.modules["pytest"] = _py_stub
spec.loader.exec_module(mod)
tests = [(n, f) for n, f in sorted(vars(mod).items())
if n.startswith("test_") and callable(f)]
passed = failed = 0
for name, fn in tests:
try:
fn()
print(f" PASS {name}")
passed += 1
except Exception:
print(f" FAIL {name}")
traceback.print_exc()
failed += 1
print(f"\n===== {passed} passed, {failed} failed / {len(tests)} =====")
sys.exit(1 if failed else 0)