python config_error ai_generated true

AssertionError: assert False + where False = <function is_valid at 0x...>(123)

ID: python/pytest-assertion-rewrite-disabled

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

版本兼容性

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

根因分析

断言重写被禁用(通过 --assert=plain、PYTHONDONTWRITEBYTECODE 或插件冲突),pytest 无法内省产生 False 的子表达式,只打印原始 assert。

English

Assertion rewriting was disabled (via --assert=plain, PYTHONDONTWRITEBYTECODE, or a plugin conflict), so pytest cannot introspect the sub-expression that produced False and prints only the raw assert.

generic

解决方案

  1. 90% 成功率
    # pytest.ini
    [pytest]
    addopts = --assert=rewrite
    # ensure no PYTHONDONTWRITEBYTECODE=1 in env
  2. 85% 成功率
    # conftest.py
    import pytest
    pytest.register_assert_rewrite('tests.test_api')

无效尝试

常见但无效的做法:

  1. 80% 失败

    -s disables output capture, not assertion rewriting; the introspection message remains absent.

  2. 60% 失败

    This defeats the purpose of pytest's introspection and pollutes test output with manual prints.