python
runtime_error
ai_generated
true
AssertionError: False is not true : expected True
ID: python/unittest-assertion-rewrite-missing
80%Fix Rate
85%Confidence
0Evidence
2024-07-30First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.10 | active | — | — | — |
| 3.11 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
In unittest, `self.assertTrue(x)` on a falsy value produces a generic message; pytest's assertion rewriting does not apply to unittest.TestCase methods, so diffs are opaque.
generic中文
在 unittest 中,对假值调用 `self.assertTrue(x)` 会生成通用消息;pytest 的断言重写不适用于 unittest.TestCase 方法,因此差异不清晰。
Workarounds
-
95% success
def test_something(): result = compute() assert result == expected # pytest shows rich diff -
85% success
self.assertEqual(result, expected) self.assertIn(item, container) self.assertIsNotNone(obj)
Dead Ends
Common approaches that don't work:
-
90% fail
Disables assertion rewriting entirely, making messages even less informative.
-
60% fail
Adds noise to test output and does not fix the underlying opaque failure; CI logs become harder to scan.
-
80% fail
Global monkeypatch affects all tests and is fragile across unittest versions.