python
config_error
ai_generated
true
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%Fix Rate
86%Confidence
0Evidence
2024-09-11First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
pytest is configured with filterwarnings = error, turning DeprecationWarning into a test failure; the code or a dependency still calls utcnow().
generic中文
pytest 配置了 filterwarnings = error,将 DeprecationWarning 变为测试失败;代码或依赖仍调用 utcnow()。
Workarounds
-
95% success
from datetime import datetime, timezone now = datetime.now(timezone.utc)
-
80% success
# pytest.ini # filterwarnings = # error # ignore:datetime.datetime.utcnow:DeprecationWarning:legacy_lib
Dead Ends
Common approaches that don't work:
-
60% fail
Hides all warnings and defeats the purpose; future breakages go unnoticed.
-
55% fail
Ignores all deprecations including ones from your own code; not targeted.