# ValueError: Dependency 'get_db' has already been overridden

- **ID:** `python/fastapi-dependency-override-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

在测试中多次覆盖同一个FastAPI依赖项

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.x | active | — | — |

## Workarounds

1. **使用context manager管理依赖项覆盖** (90% success)
   ```
   with TestClient(app) as client:
    app.dependency_overrides[get_db] = override_get_db
    response = client.get('/')
   ```
2. **在测试fixture中清理覆盖** (85% success)
   ```
   @pytest.fixture
def client():
    app.dependency_overrides = {}
    yield TestClient(app)
   ```

## Dead Ends

- **尝试使用不同的依赖项名称** — 原始依赖项仍被覆盖，新名称不匹配 (60% fail)
- **在每次测试前重置依赖项** — app.dependency_overrides是全局状态，重置可能导致测试间污染 (40% fail)
