Turning warning into errors in Jupyter

Viewed 162

I want to turn warnings into errors in Jupyter notebook running a Python 3 kernel using:

from warnings import warn, simplefilter
simplefilter('error')

While this works when using Python from the command line, this makes Jupyter crash. Has anyone run into this issue before? Would anyone know of a fix?

Thank you

1 Answers

To turn all warnings into errors you need to do:

import warnings
warnings.filterwarnings('error')

Please refer https://docs.python.org/3/library/warnings.html for more options

default                      # Show all warnings (even those ignored by default)
ignore                       # Ignore all warnings
error                        # Convert all warnings to errors
error::ResourceWarning       # Treat ResourceWarning messages as errors
default::DeprecationWarning  # Show DeprecationWarning messages
ignore,default:::mymodule    # Only report warnings triggered by "mymodule"
error:::mymodule[.*]         # Convert warnings to errors in "mymodule"
                             # and any subpackages of "mymodule"
Related