[Python-checkins] r46540 - python/trunk/Lib/test/test_struct.py

tim.peters python-checkins at python.org
Tue May 30 04:25:26 CEST 2006


Author: tim.peters
Date: Tue May 30 04:25:25 2006
New Revision: 46540

Modified:
   python/trunk/Lib/test/test_struct.py
Log:
deprecated_err():  Stop bizarre warning messages when the tests
are run in the order:

    test_genexps (or any other doctest-based test)
    test_struct
    test_doctest

The `warnings` module needs an advertised way to save/restore
its internal filter list.


Modified: python/trunk/Lib/test/test_struct.py
==============================================================================
--- python/trunk/Lib/test/test_struct.py	(original)
+++ python/trunk/Lib/test/test_struct.py	Tue May 30 04:25:25 2006
@@ -50,8 +50,12 @@
             func.__name__, args)
 
 def deprecated_err(func, *args):
+    # The `warnings` module doesn't have an advertised way to restore
+    # its filter list.  Cheat.
+    save_warnings_filters = warnings.filters[:]
     warnings.filterwarnings("error", r"""^struct.*""", DeprecationWarning)
-    warnings.filterwarnings("error", r""".*format requires.*""", DeprecationWarning)
+    warnings.filterwarnings("error", r""".*format requires.*""",
+                            DeprecationWarning)
     try:
         try:
             func(*args)
@@ -65,7 +69,7 @@
             raise TestFailed, "%s%s did not raise error" % (
                 func.__name__, args)
     finally:
-        warnings.resetwarnings()
+        warnings.filters[:] = save_warnings_filters[:]
 
 simple_err(struct.calcsize, 'Z')
 


More information about the Python-checkins mailing list