# AssertionError: 期望 200 但得到 404
assert 404 == 200

- **ID:** `python/pytest-failed-assertion-with-fixture`
- **领域:** python
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

使用 fixture 设置 HTTP 请求的测试函数期望返回 200 状态码，但由于 URL 错误或资源缺失，端点返回了 404。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Update the fixture to use the correct URL: `@pytest.fixture
def api_client():
    return Client('http://localhost:8000/api/v2')`
   ```
2. **** (95% 成功率)
   ```
   Verify the endpoint exists by testing manually with curl before running the test suite.
   ```

## 无效尝试

- **** — This masks the actual problem; the test still fails to validate the correct behavior, leading to false positives in other scenarios. (90% 失败率)
- **** — The issue is not timing-related; the server is running but the endpoint is wrong or missing, so sleeping does not help. (50% 失败率)
