33import unittest
44import warnings
55import importlib
6+ import contextlib
67
78from . import fixtures
89from importlib .metadata import (
1718)
1819
1920
21+ @contextlib .contextmanager
22+ def suppress_known_deprecation ():
23+ with warnings .catch_warnings (record = True ) as ctx :
24+ warnings .simplefilter ('default' )
25+ yield ctx
26+
27+
2028class APITests (
2129 fixtures .EggInfoPkg ,
2230 fixtures .DistInfoPkg ,
@@ -118,8 +126,7 @@ def test_entry_points_dict_construction(self):
118126 # Prior versions of entry_points() returned simple lists and
119127 # allowed casting those lists into maps by name using ``dict()``.
120128 # Capture this now deprecated use-case.
121- with warnings .catch_warnings (record = True ) as caught :
122- warnings .filterwarnings ("default" , category = DeprecationWarning )
129+ with suppress_known_deprecation () as caught :
123130 eps = dict (entry_points (group = 'entries' ))
124131
125132 assert 'main' in eps
@@ -138,8 +145,7 @@ def test_entry_points_by_index(self):
138145 See python/importlib_metadata#300 and bpo-44246.
139146 """
140147 eps = distribution ('distinfo-pkg' ).entry_points
141- with warnings .catch_warnings (record = True ) as caught :
142- warnings .filterwarnings ("default" , category = DeprecationWarning )
148+ with suppress_known_deprecation () as caught :
143149 eps [0 ]
144150
145151 # check warning
@@ -151,7 +157,7 @@ def test_entry_points_groups_getitem(self):
151157 # Prior versions of entry_points() returned a dict. Ensure
152158 # that callers using '.__getitem__()' are supported but warned to
153159 # migrate.
154- with warnings . catch_warnings ( record = True ):
160+ with suppress_known_deprecation ( ):
155161 entry_points ()['entries' ] == entry_points (group = 'entries' )
156162
157163 with self .assertRaises (KeyError ):
@@ -161,7 +167,7 @@ def test_entry_points_groups_get(self):
161167 # Prior versions of entry_points() returned a dict. Ensure
162168 # that callers using '.get()' are supported but warned to
163169 # migrate.
164- with warnings . catch_warnings ( record = True ):
170+ with suppress_known_deprecation ( ):
165171 entry_points ().get ('missing' , 'default' ) == 'default'
166172 entry_points ().get ('entries' , 'default' ) == entry_points ()['entries' ]
167173 entry_points ().get ('missing' , ()) == ()
0 commit comments