# Failed: [pytest] filterwarnings error in '...': DeprecationWarning: datetime.datetime.utcnow() 已弃用

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

## 根因

项目配置了 filterwarnings = error，将警告转为失败。第三方库或被测代码发出未在忽略列表中的 DeprecationWarning。

## 版本兼容性

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

## 解决方案

1. **** (90% 成功率)
   ```
   [tool.pytest.ini_options]
filterwarnings = [
  "error",
  "ignore:datetime.datetime.utcnow:DeprecationWarning",
  "ignore:.*is deprecated:DeprecationWarning:thirdparty.module",
]
   ```
2. **** (95% 成功率)
   ```
   # before:
from datetime import datetime
datetime.utcnow()

# after:
from datetime import datetime, timezone
datetime.now(timezone.utc)
   ```

## 无效尝试

- **** — Reintroduces noisy warnings and hides genuine deprecations you wanted to catch. (40% 失败率)
- **** — Not applied in CI where the config is used; local passes but CI fails. (70% 失败率)
