Skip to content

Commit b26a7b7

Browse files
[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 531930f) Co-authored-by: Victor Stinner <[email protected]>
1 parent 47f60c3 commit b26a7b7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Lib/test/test_generators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,7 @@ def printsolution(self, x):
21762176
caught ValueError (xyz)
21772177
21782178
>>> import warnings
2179+
>>> old_filters = warnings.filters.copy()
21792180
>>> warnings.filterwarnings("ignore", category=DeprecationWarning)
21802181
21812182
# Filter DeprecationWarning: regarding the (type, val, tb) signature of throw().
@@ -2249,8 +2250,7 @@ def printsolution(self, x):
22492250
...
22502251
ValueError: 7
22512252
2252-
>>> warnings.filters.pop(0)
2253-
('ignore', None, <class 'DeprecationWarning'>, None, 0)
2253+
>>> warnings.filters[:] = old_filters
22542254
22552255
# Re-enable DeprecationWarning: the (type, val, tb) exception representation is deprecated,
22562256
# and may be removed in a future version of Python.

0 commit comments

Comments
 (0)