]> granicus.if.org Git - python/commitdiff
prevent warning filter adjustment from altering other tests
authorBenjamin Peterson <benjamin@python.org>
Tue, 2 Mar 2010 22:23:33 +0000 (22:23 +0000)
committerBenjamin Peterson <benjamin@python.org>
Tue, 2 Mar 2010 22:23:33 +0000 (22:23 +0000)
Lib/test/test_argparse.py

index 50be6a22382cd6a7a7550a41259b9fab9c035169..7b81fc11861ee29f216b390b6b4893da76364a22 100644 (file)
@@ -19,6 +19,7 @@ import sys
 import textwrap
 import tempfile
 import unittest
+import warnings
 import argparse
 
 from test import test_support
@@ -44,29 +45,6 @@ except NameError:
             result.reverse()
         return result
 
-# silence Python 2.6 buggy warnings about Exception.message
-if sys.version_info[:2] == (2, 6):
-    import warnings
-    warnings.filterwarnings(
-        action='ignore',
-        message='BaseException.message has been deprecated as of Python 2.6',
-        category=DeprecationWarning)
-
-# silence warnings about version argument - these are expected
-import warnings
-warnings.filterwarnings(
-    action='ignore',
-    message='The "version" argument to ArgumentParser is deprecated.',
-    category=DeprecationWarning)
-warnings.filterwarnings(
-    action='ignore',
-    message='The format_version method is deprecated',
-    category=DeprecationWarning)
-warnings.filterwarnings(
-    action='ignore',
-    message='The print_version method is deprecated',
-    category=DeprecationWarning)
-
 
 class TestCase(unittest.TestCase):
 
@@ -4204,7 +4182,28 @@ class TestImportStar(TestCase):
             self.failUnless(hasattr(argparse, name))
 
 def test_main():
-    test_support.run_unittest(__name__)
+    with warnings.catch_warnings():
+        # silence Python 2.6 buggy warnings about Exception.message
+        warnings.filterwarnings(
+            action='ignore',
+            message='BaseException.message has been deprecated as of'
+            'Python 2.6',
+            category=DeprecationWarning)
+        # silence warnings about version argument - these are expected
+        warnings.filterwarnings(
+            action='ignore',
+            message='The "version" argument to ArgumentParser is deprecated.',
+            category=DeprecationWarning)
+        warnings.filterwarnings(
+            action='ignore',
+            message='The format_version method is deprecated',
+            category=DeprecationWarning)
+        warnings.filterwarnings(
+            action='ignore',
+            message='The print_version method is deprecated',
+            category=DeprecationWarning)
+
+        test_support.run_unittest(__name__)
 
 
 if __name__ == '__main__':