Index: Lib/warnings.py =================================================================== --- Lib/warnings.py (revision 61560) +++ Lib/warnings.py (working copy) @@ -7,7 +7,7 @@ import linecache __all__ = ["warn", "showwarning", "formatwarning", "filterwarnings", - "resetwarnings"] + "resetwarnings", "resettodefaults"] # filters contains a sequence of filter 5-tuples # The components of the 5-tuple are: @@ -193,6 +193,13 @@ """Clear the list of warning filters, so that no filters are active.""" filters[:] = [] +def resettodefaults(): + """Reset back to import-time filter list.""" + resetwarnings() + _processoptions(sys.warnoptions) + simplefilter("ignore", category=PendingDeprecationWarning, append=1) + simplefilter("ignore", category=ImportWarning, append=1) + class _OptionError(Exception): """Exception used by option processing helpers.""" pass @@ -269,6 +276,4 @@ return cat # Module initialization -_processoptions(sys.warnoptions) -simplefilter("ignore", category=PendingDeprecationWarning, append=1) -simplefilter("ignore", category=ImportWarning, append=1) +resettodefaults() Index: Lib/bsddb/test/test_1413192.py =================================================================== --- Lib/bsddb/test/test_1413192.py (revision 61560) +++ Lib/bsddb/test/test_1413192.py (working copy) @@ -34,11 +34,8 @@ warnings.filterwarnings('ignore', 'DBTxn aborted in destructor') -try: - context = Context() - del context -finally: - warnings.resetwarnings() +context = Context() +del context # try not to leave a turd try: Index: Lib/test/regrtest.py =================================================================== --- Lib/test/regrtest.py (revision 61560) +++ Lib/test/regrtest.py (working copy) @@ -539,6 +539,7 @@ try: save_stdout = sys.stdout + save_stderr = sys.stderr try: if cfp: sys.stdout = cfp @@ -548,6 +549,7 @@ else: # Always import it from the test package abstest = 'test.' + test + warnings.resettodefaults() start_time = time.time() the_package = __import__(abstest, globals(), locals(), []) the_module = getattr(the_package, test) @@ -563,6 +565,7 @@ test_times.append((test_time, test)) finally: sys.stdout = save_stdout + sys.stderr = save_stderr except test_support.ResourceDenied, msg: if not quiet: print test, "skipped --", msg Index: Lib/test/test_hmac.py =================================================================== --- Lib/test/test_hmac.py (revision 61560) +++ Lib/test/test_hmac.py (working copy) @@ -211,8 +211,8 @@ def digest(self): return self._x.digest() - warnings.simplefilter('error', RuntimeWarning) - try: + with test_support.catch_warning() as w: + warnings.simplefilter('error', RuntimeWarning) try: hmac.HMAC('a', 'b', digestmod=MockCrazyHash) except RuntimeWarning: @@ -227,8 +227,6 @@ pass else: self.fail('Expected warning about small block_size') - finally: - warnings.resetwarnings() Index: Lib/test/test_unicode_file.py =================================================================== --- Lib/test/test_unicode_file.py (revision 61560) +++ Lib/test/test_unicode_file.py (working copy) @@ -98,31 +98,20 @@ os.rename(filename1 + ".new", filename2) self.failUnless(os.path.isfile(filename2)) - # Try using shutil on the filenames. - try: - filename1==filename2 - except UnicodeDecodeError: - # these filenames can't be compared - shutil.copy tries to do - # just that. This is really a bug in 'shutil' - if one of shutil's - # 2 params are Unicode and the other isn't, it should coerce the - # string to Unicode with the filesystem encoding before comparison. - pass - else: - # filenames can be compared. - shutil.copy(filename1, filename2 + ".new") - os.unlink(filename1 + ".new") # remove using equiv name. - # And a couple of moves, one using each name. - shutil.move(filename1, filename2 + ".new") - self.failUnless(not os.path.exists(filename2)) - shutil.move(filename1 + ".new", filename2) - self.failUnless(os.path.exists(filename1)) - # Note - due to the implementation of shutil.move, - # it tries a rename first. This only fails on Windows when on - # different file systems - and this test can't ensure that. - # So we test the shutil.copy2 function, which is the thing most - # likely to fail. - shutil.copy2(filename1, filename2 + ".new") - os.unlink(filename1 + ".new") + shutil.copy(filename1, filename2 + ".new") + os.unlink(filename1 + ".new") # remove using equiv name. + # And a couple of moves, one using each name. + shutil.move(filename1, filename2 + ".new") + self.failUnless(not os.path.exists(filename2)) + shutil.move(filename1 + ".new", filename2) + self.failUnless(os.path.exists(filename1)) + # Note - due to the implementation of shutil.move, + # it tries a rename first. This only fails on Windows when on + # different file systems - and this test can't ensure that. + # So we test the shutil.copy2 function, which is the thing most + # likely to fail. + shutil.copy2(filename1, filename2 + ".new") + os.unlink(filename1 + ".new") def _do_directory(self, make_name, chdir_name, encoded): cwd = os.getcwd() Index: Lib/test/test_zipfile.py =================================================================== --- Lib/test/test_zipfile.py (revision 61560) +++ Lib/test/test_zipfile.py (working copy) @@ -10,6 +10,7 @@ from tempfile import TemporaryFile from random import randint, random +import warnings import test.test_support as support from test.test_support import TESTFN, run_unittest @@ -391,12 +392,17 @@ self.largeFileExceptionTest2(f, zipfile.ZIP_STORED) def zipTest(self, f, compression): - # Create the ZIP archive - zipfp = zipfile.ZipFile(f, "w", compression, allowZip64=True) - zipfp.write(TESTFN, "another"+os.extsep+"name") - zipfp.write(TESTFN, TESTFN) - zipfp.writestr("strfile", self.data) - zipfp.close() + with support.catch_warning() as w: + warnings.filterwarnings("ignore", category=DeprecationWarning) + zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED, allowZip64=True) + zipfp.write(TESTFN, "/absolute") + zipfp.close() + # Create the ZIP archive + zipfp = zipfile.ZipFile(f, "w", compression, allowZip64=True) + zipfp.write(TESTFN, "another"+os.extsep+"name") + zipfp.write(TESTFN, TESTFN) + zipfp.writestr("strfile", self.data) + zipfp.close() # Read the ZIP archive zipfp = zipfile.ZipFile(f, "r", compression) @@ -467,10 +473,12 @@ self.zipTest(f, zipfile.ZIP_DEFLATED) def testAbsoluteArcnames(self): - zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED, allowZip64=True) - zipfp.write(TESTFN, "/absolute") - zipfp.close() - + with support.catch_warning() as w: + warnings.filterwarnings("ignore", category=DeprecationWarning) + zipfp = zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED, allowZip64=True) + zipfp.write(TESTFN, "/absolute") + zipfp.close() + zipfp = zipfile.ZipFile(TESTFN2, "r", zipfile.ZIP_STORED) self.assertEqual(zipfp.namelist(), ["absolute"]) zipfp.close()