Kaydet (Commit) aba19bc4 authored tarafından Tim Peters's avatar Tim Peters

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.
üst 6067f201
...@@ -50,8 +50,12 @@ def any_err(func, *args): ...@@ -50,8 +50,12 @@ def any_err(func, *args):
func.__name__, args) func.__name__, args)
def deprecated_err(func, *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"""^struct.*""", DeprecationWarning)
warnings.filterwarnings("error", r""".*format requires.*""", DeprecationWarning) warnings.filterwarnings("error", r""".*format requires.*""",
DeprecationWarning)
try: try:
try: try:
func(*args) func(*args)
...@@ -65,7 +69,7 @@ def deprecated_err(func, *args): ...@@ -65,7 +69,7 @@ def deprecated_err(func, *args):
raise TestFailed, "%s%s did not raise error" % ( raise TestFailed, "%s%s did not raise error" % (
func.__name__, args) func.__name__, args)
finally: finally:
warnings.resetwarnings() warnings.filters[:] = save_warnings_filters[:]
simple_err(struct.calcsize, 'Z') simple_err(struct.calcsize, 'Z')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment