[Python-checkins] Fix test_generators: save/restore warnings filters (#108246)
vstinner
webhook-mailer at python.org
Mon Aug 21 19:41:17 EDT 2023
https://github.com/python/cpython/commit/531930f47f6b2a548d31e62cb4ad3e215a24bf53
commit: 531930f47f6b2a548d31e62cb4ad3e215a24bf53
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2023-08-21T23:41:13Z
summary:
Fix test_generators: save/restore warnings filters (#108246)
Previously, depending on existing filters, the test
could modify the warnings and so fail as "env changed".
files:
M Lib/test/test_generators.py
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py
index a8a344ab8de48..d48f0d47ba196 100644
--- a/Lib/test/test_generators.py
+++ b/Lib/test/test_generators.py
@@ -2258,6 +2258,7 @@ def printsolution(self, x):
caught ValueError (xyz)
>>> import warnings
+>>> old_filters = warnings.filters.copy()
>>> warnings.filterwarnings("ignore", category=DeprecationWarning)
# Filter DeprecationWarning: regarding the (type, val, tb) signature of throw().
@@ -2331,8 +2332,7 @@ def printsolution(self, x):
...
ValueError: 7
->>> warnings.filters.pop(0)
-('ignore', None, <class 'DeprecationWarning'>, None, 0)
+>>> warnings.filters[:] = old_filters
# Re-enable DeprecationWarning: the (type, val, tb) exception representation is deprecated,
# and may be removed in a future version of Python.
More information about the Python-checkins
mailing list