Answers for "warning python"

17

python suppress warnings in function

import warnings
warnings.filterwarnings("ignore")
Posted by: Guest on February-23-2020
0

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)
Posted by: Guest on May-27-2021

Python Answers by Framework

Browse Popular Code Answers by Language