python
runtime_error
ai_generated
true
DeprecationWarning: 'pytest.warns(None)' is deprecated
ID: python/pytest-deprecation-warning-as-error
80%Fix Rate
85%Confidence
0Evidence
2024-02-14First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 7.x | active | — | — | — |
| 8.x | active | — | — | — |
Root Cause
Using `pytest.warns(None)` to assert no warnings is deprecated since pytest 7; it now raises a warning that may be turned into an error.
generic中文
使用 `pytest.warns(None)` 断言无警告自 pytest 7 起已弃用;它现在会引发警告,可能被转换为错误。
Workarounds
-
90% success
import warnings with warnings.catch_warnings(): warnings.simplefilter('error') my_function() -
85% success
with pytest.warns(UserWarning): my_function()
Dead Ends
Common approaches that don't work:
-
70% fail
Hides the deprecation but does not fix the test logic; may break in future pytest versions.
-
60% fail
Does not integrate with pytest's warning capture and may miss warnings from other threads.