python
config_error
ai_generated
true
DeprecationWarning: datetime.datetime.utcnow() is deprecated FAILED tests/test_time.py::test_now - DeprecationWarning: ...
ID: python/pytest-warning-as-error-unexpected
80%Fix Rate
86%Confidence
0Evidence
2024-07-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
pytest.ini or pyproject.toml has `filterwarnings = error`, converting warnings to failures. A transitive dependency or stdlib call emits a warning that was previously ignored.
generic中文
pytest.ini 或 pyproject.toml 设置了 `filterwarnings = error`,将警告转为失败。某个传递依赖或标准库调用发出之前被忽略的警告。
Workarounds
-
90% success
Narrow the error filter to your own package: [tool.pytest.ini_options] filterwarnings = [ "error", "ignore::DeprecationWarning:thirdparty.module", ] -
95% success
Fix the offending call (e.g., replace datetime.utcnow() with datetime.now(timezone.utc)).
Dead Ends
Common approaches that don't work:
-
60% fail
Loses the protective behavior across the whole suite; real deprecations go unnoticed.
-
70% fail
Tedious and hides the root cause; new warnings still break CI unpredictably.