run_live_only.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python3
  2. """
  3. 仅跑 QiWe 真实联调(不含本地内存假数据用例),并导出真实数据报告。
  4. 用法:
  5. cd backend/tests_python
  6. python run_live_only.py
  7. """
  8. from __future__ import annotations
  9. import subprocess
  10. import sys
  11. from pathlib import Path
  12. from load_env import load_backend_env
  13. ROOT = Path(__file__).resolve().parent
  14. def main() -> int:
  15. env = load_backend_env()
  16. guid = env.get("QIWEI_GUID", "").strip()
  17. room_n = len([x for x in env.get("QIWEI_ROOM_IDS", "").split(",") if x.strip()])
  18. print("=" * 60)
  19. print("QiWe 真实联调(仅 qiwei_live,不含本地假数据)")
  20. print("=" * 60)
  21. print(f" QIWEI_GUID: {guid or '未配置'}")
  22. print(f" QIWEI_ROOM_IDS: {room_n} 个群")
  23. print("=" * 60)
  24. if not guid:
  25. print("请配置 backend/.env 中的 QIWEI_GUID")
  26. return 1
  27. cmd = [
  28. sys.executable,
  29. "-m",
  30. "pytest",
  31. "-v",
  32. "-m",
  33. "qiwei_live",
  34. "--html=report_live.html",
  35. "--self-contained-html",
  36. ]
  37. rc = subprocess.run(cmd, cwd=ROOT).returncode
  38. print()
  39. print("导出真实 QiWe 返回数据...")
  40. exp = subprocess.run([sys.executable, "export_live_data.py"], cwd=ROOT)
  41. if exp.returncode != 0:
  42. rc = exp.returncode
  43. print()
  44. if rc == 0:
  45. print("真实联调完成。交付物:")
  46. print(f" 用例报告: {ROOT / 'report_live.html'}")
  47. print(f" 数据报告: {ROOT / 'live_data_report.md'}")
  48. print(f" 数据 JSON: {ROOT / 'live_data_snapshot.json'}")
  49. return rc
  50. if __name__ == "__main__":
  51. raise SystemExit(main())