python config_error ai_generated true

DeprecationWarning: datetime.datetime.utcnow() 已弃用 FAILED tests/test_time.py::test_now - DeprecationWarning: ...

DeprecationWarning: datetime.datetime.utcnow() is deprecated FAILED tests/test_time.py::test_now - DeprecationWarning: ...

ID: python/pytest-warning-as-error-unexpected

其他格式: JSON · Markdown 中文 · English
80%修复率
86%置信度
0证据数
2024-07-14首次发现

版本兼容性

版本状态引入弃用备注
7.x active — — —
8.x active — — —

根因分析

pytest.ini 或 pyproject.toml 设置了 `filterwarnings = error`,将警告转为失败。某个传递依赖或标准库调用发出之前被忽略的警告。

English

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 60% 失败

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

  2. 70% 失败

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