Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python detect warning

# credit to Stack Overflow user in source link

import warnings

def fxn():
    warnings.warn("deprecated", DeprecationWarning)

with warnings.catch_warnings(record=True) as w:
    # Cause all warnings to always be triggered.
    warnings.simplefilter("always")
    # Trigger a warning.
    fxn()
    # Verify some things
    assert len(w) == 1
    assert issubclass(w[-1].category, DeprecationWarning)
    assert "deprecated" in str(w[-1].message)
Comment

PREVIOUS NEXT
Code Example
Python :: how to make dictionary in python 
Python :: capitalize first letter of each word python 
Python :: get last n in array python 
Python :: get the time of 1 minute later in python 
Python :: bytearray to hex python 
Python :: iterate over dataframe 
Python :: np.select with multiple conditions 
Python :: uploading folder in google colab 
Python :: pandas rename column by dictionary 
Python :: how to print correlation to a feature in pyhton 
Python :: google-api-python-client python 3 
Python :: transition from python 2 to 3 terminal 
Python :: how to get input from pyqt line edit 
Python :: How to develop a UDP echo server in python? 
Python :: what is *args and **kwargs in django 
Python :: how to create an array in python 
Python :: how to make a function in python 
Python :: python pop 
Python :: setattr python 
Python :: python imaplib send email 
Python :: how to use a function to find the average in python 
Python :: quick sort python 
Python :: python custom exception 
Python :: how to find unique values in list in python 
Python :: add list to list python 
Python :: manage.py startapp not working in django 
Python :: python - regexp to find part of an email address 
Python :: python save to excel 
Python :: discord py message link 
Python :: python get dictionary keys as list 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =