python
config_error
ai_generated
true
AssertionError: assert False + where False = <function is_valid at 0x...>(123)
ID: python/pytest-assertion-rewrite-disabled
80%Fix Rate
82%Confidence
0Evidence
2024-06-11First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
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中文
断言重写被禁用(通过 --assert=plain、PYTHONDONTWRITEBYTECODE 或插件冲突),pytest 无法内省产生 False 的子表达式,只打印原始 assert。
Workarounds
-
90% success
# pytest.ini [pytest] addopts = --assert=rewrite # ensure no PYTHONDONTWRITEBYTECODE=1 in env
-
85% success
# conftest.py import pytest pytest.register_assert_rewrite('tests.test_api')
Dead Ends
Common approaches that don't work:
-
80% fail
-s disables output capture, not assertion rewriting; the introspection message remains absent.
-
60% fail
This defeats the purpose of pytest's introspection and pollutes test output with manual prints.