Replace catch_warnings with check_warnings when it makes sense. Use assertRaises context manager to simplify some tests.
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index efe175d..cefae25 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -7,7 +7,6 @@
import textwrap
import tempfile
import unittest
-import warnings
import argparse
from StringIO import StringIO
@@ -4160,21 +4159,12 @@
self.assertTrue(hasattr(argparse, name))
def test_main():
- with warnings.catch_warnings():
- # 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)
-
+ # silence warnings about version argument - these are expected
+ with test_support.check_warnings(
+ ('The "version" argument to ArgumentParser is deprecated.',
+ DeprecationWarning),
+ ('The (format|print)_version method is deprecated',
+ DeprecationWarning)):
test_support.run_unittest(__name__)
# Remove global references to avoid looking like we have refleaks.
RFile.seen = {}