conftest.py 410 B

12345678910111213141516171819
  1. # -*- coding: utf-8 -*-
  2. import sys
  3. import os
  4. import pytest
  5. from fastapi.testclient import TestClient
  6. # 导入 main 模块,确保路径正确
  7. sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
  8. from main import create_app
  9. # 创建测试客户端
  10. app = create_app()
  11. @pytest.fixture(scope="module")
  12. def test_client():
  13. with TestClient(app) as client:
  14. yield client