Index: Lib/test/test_support.py =================================================================== --- Lib/test/test_support.py (revision 77913) +++ Lib/test/test_support.py (working copy) @@ -29,7 +29,8 @@ "run_with_locale", "set_memlimit", "bigmemtest", "bigaddrspacetest", "BasicTestRunner", "run_unittest", "run_doctest", "threading_setup", "threading_cleanup", "reap_children", "cpython_only", - "check_impl_detail", "get_attribute", "py3k_bytes"] + "check_impl_detail", "get_attribute", "py3k_bytes", + "silence_py3k_warnings"] class Error(Exception): """Base class for regression test exceptions.""" @@ -484,6 +485,23 @@ yield WarningsRecorder(w) +@contextlib.contextmanager +def silence_py3k_warnings(*filters): + """Context manager to silence py3k warnings. + + Accept 2-tuples as positional arguments: + ("message regexp", WarningCategory) + + Without argument, it defaults to: + ("", DeprecationWarning) + """ + with warnings.catch_warnings(): + if sys.py3kwarning: + for filter in filters or (("", DeprecationWarning),): + warnings.filterwarnings("ignore", *filter) + yield + + class CleanImport(object): """Context manager to force import to return a new module reference.