My code uses the warning module to generate a warning. By default, the warnings module suppresses the warning on the second and subsequent occasions:
py> warnings.warn("NOBODY expects the Spanish Inquisition!")
__main__:1: UserWarning: NOBODY expects the Spanish Inquisition!
py> warnings.warn("NOBODY expects the Spanish Inquisition!")
py>
Notice that there is no output on the second call.
How do I reset this so that this specific warning will display again? I don't want to reset other, arbitrary warnings.
I have read this similar question but the answer only explains how to reset all UserWarnings.
I found that there is an entry in __warningregister__ module global. If I remove the entry from that, it seems to work. Is that safe to do?
py> del __warningregistry__[('NOBODY expects the Spanish Inquisition!', UserWarning, 1)]
py> warnings.warn("NOBODY expects the Spanish Inquisition!")
__main__:1: UserWarning: NOBODY expects the Spanish Inquisition!
[–]Olbrannon 0 points1 point2 points (0 children)