Catch/suppress warnings
Ignacio Vazquez-Abrams
ivazqueznet at gmail.com
Tue Jan 20 14:47:00 UTC 2009
On Tue, 2009-01-20 at 09:20 -0500, James Laska wrote:
> Greetings folks,
>
> I'm finishing up some work for Chris Lumens to add unittests into
> pykickstart. I'm trying to reduce the expected noise of some tests and
> would like to capture or suppress any warnings displayed.
>
> Chris directed me to
> http://docs.python.org/library/warnings.html#temporarily-suppressing-warnings, which most likely works. But I'm looking for something a bit more backwards compatible (that doesn't use the new with: syntax).
The with syntax isn't the biggest backwards compatibility issue there.
But that's a topic for another day.
> Any suggestions or experiences to share?
Here's a little chunk of code I used for doctests:
def _test():
sw = warnings.showwarning
def showwarning(msg, cat, fname, lno, file=None):
sw(msg, cat, fname.split('/')[-1], 0, sys.stdout)
warnings.showwarning = showwarning
warnings.simplefilter('always')
import doctest
doctest.testmod()
--
Ignacio Vazquez-Abrams <ivazqueznet at gmail.com>
PLEASE don't CC me; I'm already subscribed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://listman.redhat.com/archives/fedora-python-devel-list/attachments/20090120/0360e620/attachment.sig>
More information about the Fedora-python-devel-list
mailing list