run_tests.py 1.4 KB
"""Direct runner for the forum log monitor integration tests."""

import sys
from pathlib import Path


PROJECT_ROOT = Path(__file__).resolve().parents[3]

if str(PROJECT_ROOT) not in sys.path:
    sys.path.insert(0, str(PROJECT_ROOT))


from tests.integration.forum.test_monitor import TestLogMonitor


def main():
    """Run the forum log monitor tests without requiring pytest."""
    print("=" * 60)
    print("ForumEngine 日志解析集成测试")
    print("=" * 60)
    print()

    test_instance = TestLogMonitor()
    test_methods = [name for name in dir(test_instance) if name.startswith("test_")]

    passed = 0
    failed = 0

    for test_method_name in test_methods:
        test_method = getattr(test_instance, test_method_name)
        print(f"运行测试: {test_method_name}...", end=" ")
        try:
            test_instance.setup_method()
            try:
                test_method()
            finally:
                test_instance.teardown_method()
            print("✓ 通过")
            passed += 1
        except AssertionError as exc:
            print(f"✗ 失败: {exc}")
            failed += 1
        except Exception as exc:
            print(f"✗ 错误: {exc}")
            failed += 1

    print()
    print("=" * 60)
    print(f"测试结果: {passed} 通过, {failed} 失败")
    print("=" * 60)

    raise SystemExit(1 if failed else 0)


if __name__ == "__main__":
    main()