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

Also available as: JSON · Markdown · 中文
80%Fix Rate
86%Confidence
0Evidence
2024-07-14First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
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

  1. 90% success
    Narrow the error filter to your own package:
      [tool.pytest.ini_options]
      filterwarnings = [
        "error",
        "ignore::DeprecationWarning:thirdparty.module",
      ]
  2. 95% success
    Fix the offending call (e.g., replace datetime.utcnow() with datetime.now(timezone.utc)).

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Loses the protective behavior across the whole suite; real deprecations go unnoticed.

  2. 70% fail

    Tedious and hides the root cause; new warnings still break CI unpredictably.