我们有一个 FastApi 应用程序并使用 httpx AsyncClient 进行测试。我们遇到了单元测试在本地运行良好但在 CI 服务器(Github 操作)上失败的问题。
经过进一步研究,我们通过设置为遇到了这个建议的解决方案。raise_server_exceptions=False
False
client = TestClient(app, raise_server_exceptions=False)
但是,这是针对同步客户端的。我们正在使用异步客户端。
@pytest.fixture
async def client(test_app):
async with AsyncClient(app=test_app, base_url="http://testserver") as client:
yield client
AsyncClient 不支持该raise_app_exceptions=False
选项。
这个事情谁有经验?谢谢