Skip to content

Commit 531930f

Browse files
authored
Fix test_generators: save/restore warnings filters (#108246)
Previously, depending on existing filters, the test could modify the warnings and so fail as "env changed".
1 parent a1cc74c commit 531930f

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
@@ -2258,6 +2258,7 @@ def printsolution(self, x):
22582258
caught ValueError (xyz)
22592259
22602260
>>> import warnings
2261+
>>> old_filters = warnings.filters.copy()
22612262
>>> warnings.filterwarnings("ignore", category=DeprecationWarning)
22622263
22632264
# Filter DeprecationWarning: regarding the (type, val, tb) signature of throw().
@@ -2331,8 +2332,7 @@ def printsolution(self, x):
23312332
...
23322333
ValueError: 7
23332334
2334-
>>> warnings.filters.pop(0)
2335-
('ignore', None, <class 'DeprecationWarning'>, None, 0)
2335+
>>> warnings.filters[:] = old_filters
23362336
23372337
# Re-enable DeprecationWarning: the (type, val, tb) exception representation is deprecated,
23382338
# and may be removed in a future version of Python.

0 commit comments

Comments
 (0)