test_main.py 529 B

12345678910111213141516171819202122
  1. # -*- coding: utf-8 -*-
  2. """
  3. 测试文件
  4. 注意:使用普通的 def 定义测试函数,不要使用 async def
  5. 执行命令: pytest tests/test.py
  6. """
  7. import pytest
  8. from fastapi.testclient import TestClient
  9. def test_check_health(test_client: TestClient):
  10. """测试健康检查接口"""
  11. response = test_client.get("/common/health")
  12. assert response.status_code == 200
  13. assert response.json() == {"msg": "Healthy"}
  14. # 运行所有测试
  15. if __name__ == "__main__":
  16. pytest.main(["-v", "tests/test_main.py"])