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

- **ID:** `python/pytest-warnings-as-errors-failing-ci`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

CI 使用 `-W error`（或配置中的 `filterwarnings = error`）运行 pytest，因此测试执行期间抛出的任何 DeprecationWarning 都会变成失败。这通常在 Python 小版本升级后出现。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.12 | active | — | — |
| 3.13 | active | — | — |

## 解决方案

1. **** (90% 成功率)
   ```
   Ignore specific known-safe warnings via pytest config:

# pyproject.toml
[tool.pytest.ini_options]
filterwarnings = [
  "error",
  "ignore:datetime.datetime.utcnow\(\) is deprecated:DeprecationWarning",
]
   ```
2. **** (98% 成功率)
   ```
   Fix the deprecated call site:

from datetime import datetime, timezone
datetime.now(timezone.utc)  # replaces utcnow()
   ```

## 无效尝试

- **** — Hides all warnings, including ones the team intentionally turned into errors to catch regressions. (60% 失败率)
- **** — Only suppresses in that scope; other tests using the same deprecated API still fail. (70% 失败率)
