python
config_error
ai_generated
true
DeprecationWarning: datetime.datetime.utcnow() 已弃用并计划在未来版本中移除。 E DeprecationWarning: datetime.datetime.utcnow() 已弃用
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. E DeprecationWarning: datetime.datetime.utcnow() is deprecated
ID: python/pytest-deprecationwarning-as-error
80%修复率
86%置信度
0证据数
2024-09-11首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
pytest 配置了 filterwarnings = error,将 DeprecationWarning 变为测试失败;代码或依赖仍调用 utcnow()。
English
pytest is configured with filterwarnings = error, turning DeprecationWarning into a test failure; the code or a dependency still calls utcnow().
解决方案
-
95% 成功率
from datetime import datetime, timezone now = datetime.now(timezone.utc)
-
80% 成功率
# pytest.ini # filterwarnings = # error # ignore:datetime.datetime.utcnow:DeprecationWarning:legacy_lib
无效尝试
常见但无效的做法:
-
60% 失败
Hides all warnings and defeats the purpose; future breakages go unnoticed.
-
55% 失败
Ignores all deprecations including ones from your own code; not targeted.