python
type_error
ai_generated
true
TypeError: assertRaises() missing 1 required positional argument: 'callable'
ID: python/unittest-assertraises-no-context
80%Fix Rate
89%Confidence
0Evidence
2024-03-06First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
| 3.12 | active | — | — | — |
Root Cause
`assertRaises` is used as `with self.assertRaises(ValueError):` but the exception type is passed as a string or the callable form is used incorrectly.
generic中文
`assertRaises` 以 `with self.assertRaises(ValueError):` 形式使用,但异常类型被传为字符串或可调用形式使用不当。
Workarounds
-
97% success
Use the context manager form correctly: with self.assertRaises(ValueError): parse('bad') Or the callable form: self.assertRaises(ValueError, parse, 'bad')
Dead Ends
Common approaches that don't work:
-
80% fail
Strings are not exception classes; raises TypeError or fails silently.
-
70% fail
Catches all exceptions and hides real bugs.