From cbef8aab4897a69617604b669d6854479be8f44e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 22 Aug 2023 01:41:13 +0200 Subject: [PATCH] Fix test_generators: save/restore warnings filters (GH-108246) Previously, depending on existing filters, the test could modify the warnings and so fail as "env changed". (cherry picked from commit 531930f47f6b2a548d31e62cb4ad3e215a24bf53) Co-authored-by: Victor Stinner --- Lib/test/test_generators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 31680b5a92e0f3..1ee9958445bf18 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -2176,6 +2176,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(). @@ -2249,8 +2250,7 @@ def printsolution(self, x): ... ValueError: 7 ->>> warnings.filters.pop(0) -('ignore', None, , 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.