python
config_error
ai_generated
true
DeprecationWarning: datetime.datetime.utcnow() is deprecated FAILED tests/test_time.py::test_now - DeprecationWarning: ...
ID: python/pytest-warnings-as-errors-failing-ci
80%Fix Rate
85%Confidence
0Evidence
2024-06-11First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.12 | active | — | — | — |
| 3.13 | active | — | — | — |
Root Cause
CI runs pytest with `-W error` (or `filterwarnings = error` in config), so any DeprecationWarning raised during test execution becomes a failure. This often appears after a Python minor upgrade.
generic中文
CI 使用 `-W error`(或配置中的 `filterwarnings = error`)运行 pytest,因此测试执行期间抛出的任何 DeprecationWarning 都会变成失败。这通常在 Python 小版本升级后出现。
Workarounds
-
90% success
Ignore specific known-safe warnings via pytest config: # pyproject.toml [tool.pytest.ini_options] filterwarnings = [ "error", "ignore:datetime.datetime.utcnow\(\) is deprecated:DeprecationWarning", ]
-
98% success
Fix the deprecated call site: from datetime import datetime, timezone datetime.now(timezone.utc) # replaces utcnow()
Dead Ends
Common approaches that don't work:
-
60% fail
Hides all warnings, including ones the team intentionally turned into errors to catch regressions.
-
70% fail
Only suppresses in that scope; other tests using the same deprecated API still fail.