]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Fix test_generators: save/restore warnings filters (GH-108246) (#108249)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 22 Aug 2023 10:00:07 +0000 (03:00 -0700)
committerGitHub <noreply@github.com>
Tue, 22 Aug 2023 10:00:07 +0000 (12:00 +0200)
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 <vstinner@python.org>
Lib/test/test_generators.py

index 31680b5a92e0f3ca7fae166b296d2136c2af01fa..1ee9958445bf1851456bab10b74800f8254567f2 100644 (file)
@@ -2176,6 +2176,7 @@ caught ValueError ()
 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 @@ Traceback (most recent call last):
   ...
 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.