# RuntimeError: 当另一个循环正在运行时无法运行事件循环

- **ID:** `python/starlette-testclient-blocking-async`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在已有运行循环的异步测试中调用 asyncio.run() 或 loop.run_until_complete，常见于混用 TestClient 和 AsyncClient。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (92% 成功率)
   ```
   Use httpx.AsyncClient(transport=ASGITransport(app=app), base_url='http://test') with pytest.mark.asyncio
   ```
2. **** (90% 成功率)
   ```
   await the call directly: response = await client.get('/')
   ```

## 无效尝试

- **** — Patches loop globally and can mask other async bugs. (55% 失败率)
- **** — TestClient blocks; cannot test concurrent async behavior. (60% 失败率)
