# AssertionError: 依赖覆盖未生效：响应仍使用生产数据库

- **ID:** `python/fastapi-dependency-override-not-applied`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在测试中使用的app实例与dependency_overrides设置的实例不同，或者未在测试后清理覆盖。

## 版本兼容性

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

## 解决方案

1. **** (95% 成功率)
   ```
   client = TestClient(app)\napp.dependency_overrides[get_db] = fake_db
   ```
2. **** (93% 成功率)
   ```
   @pytest.fixture\ndef client():\n    yield TestClient(app)\n    app.dependency_overrides.clear()
   ```

## 无效尝试

- **** — If the TestClient uses a different app, overrides never apply. (70% 失败率)
- **** — FastAPI resolves via dependency_overrides, not module lookup. (80% 失败率)
