Skip to main content

ignore_warnings

This class provides a context manager and decorator for suppressing specific warnings during test execution. It dynamically selects between simple and complex warning filters based on the provided criteria, such as messages or module names. The class manages the lifecycle of warning suppression by entering and exiting a controlled warning state.

Attributes

AttributeTypeDescription
ignore_kwargsdictA dictionary of keyword arguments passed to the warning filter function to specify which warnings should be suppressed.
filter_funccallableThe specific warnings module function used to apply the ignore filter, determined by whether 'message' or 'module' keys are present in the ignore arguments.
catch_warningswarnings.catch_warningsThe context manager instance used to locally scope warning suppression during the decorator's enabled state.

Constructor

Signature

def ignore_warnings(
**kwargs: dict
) - > null

Parameters

NameTypeDescription
**kwargsdictKeyword arguments used to filter warnings, such as 'message' or 'module'.

Methods


enable()

@classmethod
def enable()

Activates the warning suppression by entering a warning-catching context and applying the configured ignore filters.


disable()

@classmethod
def disable()

Deactivates the warning suppression by exiting the warning-catching context and restoring previous warning settings.