# DeprecationWarning: datetime.datetime.utcnow() 已弃用
FAILED tests/test_time.py::test_now - DeprecationWarning: ...

- **ID:** `python/pytest-warning-as-error-unexpected`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest.ini 或 pyproject.toml 设置了 `filterwarnings = error`，将警告转为失败。某个传递依赖或标准库调用发出之前被忽略的警告。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   Narrow the error filter to your own package:
  [tool.pytest.ini_options]
  filterwarnings = [
    "error",
    "ignore::DeprecationWarning:thirdparty.module",
  ]
   ```
2. **** (95% 成功率)
   ```
   Fix the offending call (e.g., replace datetime.utcnow() with datetime.now(timezone.utc)).
   ```

## 无效尝试

- **** — Loses the protective behavior across the whole suite; real deprecations go unnoticed. (60% 失败率)
- **** — Tedious and hides the root cause; new warnings still break CI unpredictably. (70% 失败率)
