diff Lib/test/test_struct.py @ 48455:b5cf0cb0c7ce

Make test.test_support.catch_warnings more robust as discussed on python-dev. Also add explicit tests for it to test_warnings. (forward port of r64910 from trunk)
author Nick Coghlan <ncoghlan@gmail.com>
date Sun, 13 Jul 2008 12:25:08 +0000
parents 5f9435317de1
children 3e6e565ee30a
line wrap: on
line diff
--- a/Lib/test/test_struct.py	Sun Jul 13 01:38:36 2008 +0000
+++ b/Lib/test/test_struct.py	Sun Jul 13 12:25:08 2008 +0000
@@ -35,12 +35,9 @@
     @wraps(func)
     def decorator(*args, **kw):
         with catch_warning():
-            # Grrr, we need this function to warn every time.  Without removing
-            # the warningregistry, running test_tarfile then test_struct would fail
-            # on 64-bit platforms.
-            globals = func.__globals__
-            if '__warningregistry__' in globals:
-                del globals['__warningregistry__']
+            # We need this function to warn every time, so stick an
+            # unqualifed 'always' at the head of the filter list
+            warnings.simplefilter("always")
             warnings.filterwarnings("error", category=DeprecationWarning)
             return func(*args, **kw)
     return decorator
@@ -53,7 +50,7 @@
         pass
     except DeprecationWarning:
         if not PY_STRUCT_OVERFLOW_MASKING:
-            raise TestFailed("%s%s expected to raise struct.error" % (
+            raise TestFailed("%s%s expected to raise DeprecationWarning" % (
                 func.__name__, args))
     else:
         raise TestFailed("%s%s did not raise error" % (