python
runtime_error
ai_generated
true
Failed: DID NOT RAISE <class 'ValueError'>
ID: python/pytest-assert-raises-no-exception
80%Fix Rate
84%Confidence
0Evidence
2025-02-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.7 | active | — | — | — |
Root Cause
使用pytest.raises期望抛出特定异常,但代码没有抛出,导致测试失败。
generic中文
pytest.raises期望异常,但代码未抛出,测试失败。
Workarounds
-
95% success
def func(): raise ValueError('invalid') with pytest.raises(ValueError): func() -
90% success
with pytest.raises(ValueError, match='invalid'): func()
Dead Ends
Common approaches that don't work:
-
90% fail
掩盖了代码逻辑错误。
-
70% fail
与pytest.raises冲突,且不必要。