diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-03-02 22:23:33 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-03-02 22:23:33 (GMT) |
commit | 4aa8a13b8630e7c3a828bf94199faed5e4311bf2 (patch) | |
tree | 5ec812c69e99e59441970ddbac298ab36175f99b | |
parent | 036fae39ac842103ea84b6fb2d7b3b9973abc5e1 (diff) | |
download | cpython-4aa8a13b8630e7c3a828bf94199faed5e4311bf2.zip cpython-4aa8a13b8630e7c3a828bf94199faed5e4311bf2.tar.gz cpython-4aa8a13b8630e7c3a828bf94199faed5e4311bf2.tar.bz2 |
prevent warning filter adjustment from altering other tests
-rw-r--r-- | Lib/test/test_argparse.py | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py index 50be6a2..7b81fc1 100644 --- a/Lib/test/test_argparse.py +++ b/Lib/test/test_argparse.py @@ -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__': |