summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_struct.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2006-12-13 23:09:53 (GMT)
committerBrett Cannon <bcannon@gmail.com>2006-12-13 23:09:53 (GMT)
commit6d9520c4f0e01ff87ff3d74166f508df0a215261 (patch)
tree4024486982a7efc6717ead6db1e0e44105bb27b6 /Lib/test/test_struct.py
parentc745df8519b3dce95bb3ce7587c4c311f8184290 (diff)
downloadcpython-6d9520c4f0e01ff87ff3d74166f508df0a215261.zip
cpython-6d9520c4f0e01ff87ff3d74166f508df0a215261.tar.gz
cpython-6d9520c4f0e01ff87ff3d74166f508df0a215261.tar.bz2
Add test.test_support.guard_warnings_filter . This function returns a context
manager that protects warnings.filter from being modified once the context is exited.
Diffstat (limited to 'Lib/test/test_struct.py')
-rw-r--r--Lib/test/test_struct.py25
1 files changed, 10 insertions, 15 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py
index 66fd667..0144a0f 100644
--- a/Lib/test/test_struct.py
+++ b/Lib/test/test_struct.py
@@ -50,22 +50,17 @@ def any_err(func, *args):
def with_warning_restore(func):
def _with_warning_restore(*args, **kw):
- # The `warnings` module doesn't have an advertised way to restore
- # its filter list. Cheat.
- save_warnings_filters = warnings.filters[:]
- # 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.func_globals
- if '__warningregistry__' in globals:
- del globals['__warningregistry__']
- warnings.filterwarnings("error", r"""^struct.*""", DeprecationWarning)
- warnings.filterwarnings("error", r""".*format requires.*""",
- DeprecationWarning)
- try:
+ with test.test_support.guard_warnings_filter():
+ # 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.func_globals
+ if '__warningregistry__' in globals:
+ del globals['__warningregistry__']
+ warnings.filterwarnings("error", r"""^struct.*""", DeprecationWarning)
+ warnings.filterwarnings("error", r""".*format requires.*""",
+ DeprecationWarning)
return func(*args, **kw)
- finally:
- warnings.filters[:] = save_warnings_filters[:]
return _with_warning_restore
def deprecated_err(func, *args):