classification
Title: warnings module offers no documented, programmatic way to reset "seen-warning" flag
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution: duplicate
Dependencies: Superseder: warnings module offers no documented, programmatic way to reset "seen-warning" flag
View: 20131
Assigned To: Nosy List: inducer, r.david.murray
Priority: normal Keywords:

Created on 2014-01-05 12:39 by inducer, last changed 2021-01-11 20:26 by iritkatriel.

Messages (2)
msg207372 - (view) Author: Andreas Kloeckner (inducer) Date: 2014-01-05 12:39
For tests and doctests, it is often desirable to show or verify that a certain warning occurs. Unfortunately, if the warning has been hit previously, it will not be issued again. It would be great if there were a documented, unified way to reset this 'seen' flag.

Related stackoverflow posts showing that I'm not the first person to have this need:

* https://stackoverflow.com/questions/19428761/python-showing-once-warnings-again-resetting-all-warning-registries
* https://stackoverflow.com/questions/2418570/testing-warnings-with-doctest

Neither of these has a satisfactory solution.
msg207390 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-01-05 18:30
The easy answer for unittest is to use assertWarns.  For versions where that doesn't exist you could implement the same technique yourself.  Exposing a 'clear everything' function in the warnings module might not be a bad idea, but otherwise for doctest I'd think the catch_warnings context manager would be the correct answer, and that is documented.

Given the above, I guess this issue is a request to expose a "clear everything" function in the warnings module, which I think is a reasonable idea.

(I think it would be nice to add some support stuff to doctest to make things like this easier, but that is a totally separate issue.)
History
Date User Action Args
2021-01-11 20:26:02iritkatrielsetsuperseder: warnings module offers no documented, programmatic way to reset "seen-warning" flag
resolution: duplicate
2021-01-11 20:26:02iritkatriellinkissue20131 superseder
2020-03-18 18:34:23brett.cannonsetnosy: - brett.cannon
2014-01-10 22:44:06terry.reedysetstage: test needed
2014-01-05 18:30:51r.david.murraysetnosy: + r.david.murray, brett.cannon

messages: + msg207390
versions: + Python 3.5, - Python 2.7, Python 3.4
2014-01-05 12:39:43inducersettype: enhancement
2014-01-05 12:39:29inducercreate