Re: Python 2.7 disables deprecation warnings by default

Jim Fulton <[email protected]>
Newsgroups gmane.comp.web.zope.devel
Message-ID <[email protected]>
On Wed, Jul 7, 2010 at 9:59 AM, Tres Seaver <[email protected]> wrote:
>> Individual test modules can do this, but I'm uncomfortable having a
>> test script make a global setting like this and the warning module
>> doesn't seem to provide a way to capture the current state so it can
>> be reset after running tests.
>
> As of Python 2.6, the warnings module sports a context manager::
>
>  with warnings.catch_warnings():
>    warnings.simplefilter("default")
>    fxn()

Ah, this works because catch_warnings saves and later restores the
filter configuration. Cool.

Jim

-- 
Jim Fulton
_______________________________________________
Zope-Dev maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 https://mail.zope.org/mailman/listinfo/zope-announce
 https://mail.zope.org/mailman/listinfo/zope )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.