[3.12] Fix test_generators: save/restore warnings filters (GH-108246) (#108249)

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 531930f47f)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2023-08-22 03:00:07 -07:00 committed by GitHub
parent 47f60c3f67
commit b26a7b78c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View 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.