title: How do I disable and then re-enable a warning?
body: <p>I'm writing some unit tests for a Python library and would like certain warnings to be raised as exceptions, which I can easily do with the <a href="http://docs.python.org/library/warnings.html#warnings.simplefilter" rel="noreferrer">simplefilter</a> function.  However, for one test I'd like to disable the warning, run the test, then re-enable the warning.</p>
  
  <p>I'm using Python 2.6, so I'm supposed to be able to do that with the <a href="http://docs.python.org/library/warnings.html#warnings.catch_warnings" rel="noreferrer">catch_warnings</a> context manager, but it doesn't seem to work for me.  Even failing that, I should also be able to call <a href="http://docs.python.org/library/warnings.html#warnings.resetwarnings" rel="noreferrer">resetwarnings</a> and then re-set my filter.</p>
  
  <p>Here's a simple example which illustrates the problem:</p>
  
  <pre><code>&gt;&gt;&gt; import warnings
  &gt;&gt;&gt; warnings.simplefilter("error", UserWarning)
  &gt;&gt;&gt; 
  &gt;&gt;&gt; def f():
  ...     warnings.warn("Boo!", UserWarning)
  ... 
  &gt;&gt;&gt; 
  &gt;&gt;&gt; f() # raises UserWarning as an exception
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "&lt;stdin&gt;", line 2, in f
  UserWarning: Boo!
  &gt;&gt;&gt; 
  &gt;&gt;&gt; f() # still raises the exception
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "&lt;stdin&gt;", line 2, in f
  UserWarning: Boo!
  &gt;&gt;&gt; 
  &gt;&gt;&gt; with warnings.catch_warnings():
  ...     warnings.simplefilter("ignore")
  ...     f()     # no warning is raised or printed
  ... 
  &gt;&gt;&gt; 
  &gt;&gt;&gt; f() # this should raise the warning as an exception, but doesn't
  &gt;&gt;&gt; 
  &gt;&gt;&gt; warnings.resetwarnings()
  &gt;&gt;&gt; warnings.simplefilter("error", UserWarning)
  &gt;&gt;&gt; 
  &gt;&gt;&gt; f() # even after resetting, I'm still getting nothing
  &gt;&gt;&gt; 
  </code></pre>
  
  <p>Can someone explain how I can accomplish this?</p>
  
  <p>EDIT: Apparently this is a known bug: <a href="http://bugs.python.org/issue4180" rel="noreferrer">http://bugs.python.org/issue4180</a></p>