You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: mechanism for failing when warnings are issued without conversion to exceptions? #11518
Maybe this is rather niche, or more of a usage query, but I think it has confused us a little bit. One conundrum we occasionally face in SciPy is that the heavily-used NumPy library sometimes decides to issue warnings for some function calls, but the same code paths can also have try/except guards for various reasons.
So, when we try to proactively turn warnings into errors in filterwarnings in our pytest.ini, what we end up with is a case where a warning becomes invisible to our testsuite/CI testing, and we miss out on i.e., deprecation warnings by the very mechanism we are trying to use to discover them, because the try/except block is triggered via pytest and then handled gracefully by NumPy to end up in a warning-free scenario!
Do you think there's a valid feature request in here? Or should we just resign ourselves to i.e., a CI job that runs the testsuite with the "warnings->errors" disabled and then greps on the pytest summary and errors out on non-zero warnings accounting?
I'd consider this a bug in Numpy: the code described in scipy/scipy#18781 (comment) is going to give the wrong answer if users have warnings-as-errors, and for that matter if they try to ctrl-c it'll misbehave badly too. Instead of
Closing as resolved: pytest now has a --max-warnings/max_warnings option (#14372, closing #14371) that fails the run based on the post-test warnings summary count without requiring filterwarnings = error, which is exactly the feature discussed here and avoids the try/except-swallowing problem described above.
(I do also think that hiding warnings when end-users set -Werror is regrettable though)
Activity
RonnyPfannschmidt commentedon Oct 18, 2023
This is a dupe, let me find the one I made
RonnyPfannschmidt commentedon Oct 18, 2023
#10098 is not quite a dupe but similar enough
I propose post test warnings failure as a feature
Zac-HD commentedon Oct 21, 2023
I'd consider this a bug in Numpy: the code described in scipy/scipy#18781 (comment) is going to give the wrong answer if users have warnings-as-errors, and for that matter if they try to ctrl-c it'll misbehave badly too. Instead of
you should do something like
Zac-HD commentedon Jul 22, 2026
Closing as resolved: pytest now has a
--max-warnings/max_warningsoption (#14372, closing #14371) that fails the run based on the post-test warnings summary count without requiringfilterwarnings = error, which is exactly the feature discussed here and avoids the try/except-swallowing problem described above.(I do also think that hiding warnings when end-users set
-Werroris regrettable though)