python
config_error
ai_generated
true
Failed: [pytest] filterwarnings error in '...': DeprecationWarning: datetime.datetime.utcnow() 已弃用
Failed: [pytest] filterwarnings error in '...': DeprecationWarning: datetime.datetime.utcnow() is deprecated
ID: python/pytest-warning-as-error-failed
80%修复率
86%置信度
0证据数
2024-11-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
根因分析
项目配置了 filterwarnings = error,将警告转为失败。第三方库或被测代码发出未在忽略列表中的 DeprecationWarning。
English
The project configures filterwarnings = error, turning warnings into failures. A third-party library or the code under test emits a DeprecationWarning that is not in the ignore list.
解决方案
-
90% 成功率
[tool.pytest.ini_options] filterwarnings = [ "error", "ignore:datetime.datetime.utcnow:DeprecationWarning", "ignore:.*is deprecated:DeprecationWarning:thirdparty.module", ]
-
95% 成功率
# before: from datetime import datetime datetime.utcnow() # after: from datetime import datetime, timezone datetime.now(timezone.utc)
无效尝试
常见但无效的做法:
-
40% 失败
Reintroduces noisy warnings and hides genuine deprecations you wanted to catch.
-
70% 失败
Not applied in CI where the config is used; local passes but CI fails.