class clear_and_catch_warnings(warnings.catch_warnings):
Context manager that resets warning registry for catching warnings
Warnings can be slippery, because, whenever a warning is triggered, Python
adds a __warningregistry__ member to the calling module. This makes
it impossible to retrigger the warning in this module, whatever you put in
the warnings filters. This context manager accepts a sequence of modules
as a keyword argument to its constructor and:
modules
on entry;This makes it possible to trigger any warning afresh inside the context manager without disturbing the state of warnings outside.
For compatibility with Python 3.0, please consider all arguments to be keyword-only.
>>> import warnings >>> with np.testing.clear_and_catch_warnings( ... modules=[np.core.fromnumeric]): ... warnings.simplefilter('always') ... warnings.filterwarnings('ignore', module='np.core.fromnumeric') ... # do something that raises a warning but ignore those in ... # np.core.fromnumeric
Method | __enter__ |
Undocumented |
Method | __exit__ |
Undocumented |
Method | __init__ |
Undocumented |
Class Variable | class_modules |
Undocumented |
Instance Variable | _warnreg_copies |
Undocumented |
Instance Variable | modules |
Undocumented |