]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix test_generators: save/restore warnings filters (#108246)
authorVictor Stinner <vstinner@python.org>
Mon, 21 Aug 2023 23:41:13 +0000 (01:41 +0200)
committerGitHub <noreply@github.com>
Mon, 21 Aug 2023 23:41:13 +0000 (23:41 +0000)
Previously, depending on existing filters, the test
could modify the warnings and so fail as "env changed".

Lib/test/test_generators.py

index a8a344ab8de48dfd8da5ffa592081d48450b51e3..d48f0d47ba1962ba238c9f8c634d62059a8d7178 100644 (file)
@@ -2258,6 +2258,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().
@@ -2331,8 +2332,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.