1# Warnings as errors for all the program
2import warnings
3warnings.filterwarnings("error")
4
5
6# Warnings as errors whithin block
7import warnings
8with warnings.catch_warnings():
9 warnings.simplefilter("error")
10 # Code in this block will raise exception for a warning
1import warnings
2
3def fxn():
4 warnings.warn("deprecated", DeprecationWarning)
5
6with warnings.catch_warnings():
7 warnings.simplefilter("ignore")
8 fxn()