python
config_error
ai_generated
true
DeprecationWarning: datetime.datetime.utcnow() 已弃用并计划移除
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal
ID: python/pytest-warnings-as-errors-failure
80%修复率
87%置信度
0证据数
2025-11-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
| 3.13 | active | — | — | — |
根因分析
测试套件以 -W error 或 filterwarnings=error 运行,将应用或第三方代码的 DeprecationWarning 升级为测试失败。
English
The test suite runs with -W error or filterwarnings=error, promoting a DeprecationWarning from application or third-party code into a test failure.
解决方案
-
95% 成功率
from datetime import datetime, timezone dt = datetime.now(timezone.utc)
-
88% 成功率
# pyproject.toml [tool.pytest.ini_options] filterwarnings = [ "error", "ignore::DeprecationWarning:legacy_lib.*", "ignore:datetime.datetime.utcnow:DeprecationWarning", ]
无效尝试
常见但无效的做法:
-
85% 失败
noqa is for linters; pytest's warning filter isn't affected by inline noqa comments.
-
70% 失败
Doesn't fix the deprecated call; the warning still fires elsewhere in the codebase.