3
3
import unittest
4
4
import warnings
5
5
import importlib
6
+ import contextlib
6
7
7
8
from . import fixtures
8
9
from importlib_metadata import (
17
18
)
18
19
19
20
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
+
20
28
class APITests (
21
29
fixtures .EggInfoPkg ,
22
30
fixtures .DistInfoPkg ,
@@ -122,7 +130,7 @@ def test_entry_points_dict_construction(self):
122
130
allowed casting those lists into maps by name using ``dict()``.
123
131
Capture this now deprecated use-case.
124
132
"""
125
- with warnings . catch_warnings ( record = True ) as caught :
133
+ with suppress_known_deprecation ( ) as caught :
126
134
eps = dict (entry_points (group = 'entries' ))
127
135
128
136
assert 'main' in eps
@@ -141,7 +149,7 @@ def test_entry_points_by_index(self):
141
149
See python/importlib_metadata#300 and bpo-44246.
142
150
"""
143
151
eps = distribution ('distinfo-pkg' ).entry_points
144
- with warnings . catch_warnings ( record = True ) as caught :
152
+ with suppress_known_deprecation ( ) as caught :
145
153
eps [0 ]
146
154
147
155
# check warning
@@ -155,7 +163,7 @@ def test_entry_points_groups_getitem(self):
155
163
that callers using '.__getitem__()' are supported but warned to
156
164
migrate.
157
165
"""
158
- with warnings . catch_warnings ( record = True ):
166
+ with suppress_known_deprecation ( ):
159
167
entry_points ()['entries' ] == entry_points (group = 'entries' )
160
168
161
169
with self .assertRaises (KeyError ):
@@ -167,7 +175,7 @@ def test_entry_points_groups_get(self):
167
175
that callers using '.get()' are supported but warned to
168
176
migrate.
169
177
"""
170
- with warnings . catch_warnings ( record = True ):
178
+ with suppress_known_deprecation ( ):
171
179
entry_points ().get ('missing' , 'default' ) == 'default'
172
180
entry_points ().get ('entries' , 'default' ) == entry_points ()['entries' ]
173
181
entry_points ().get ('missing' , ()) == ()
0 commit comments