Testing and Diagnostics Modules
warnings
Emits and filters nonfatal diagnostic warnings using categories and configurable actions. A warning can be hidden, displayed or converted into an exception. Use catch_warnings to temporarily change filters or record warnings; Python 3.13 warning filter state is process-wide.
Formal Syntax & Structure
python syntaxpython
import warningsReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import warningswith warnings.catch_warnings(record=True) as caught: warnings.simplefilter("always") warnings.warn("old API", DeprecationWarning) print(caught[0].category.__name__)