Skip to content

Commit 1cf8424

Browse files
authored
bpo-44784: Apply changes from importlib_metadata 4.6.3 (GH-27508)
Addressing issues with tests under error on warnings. Automerge-Triggered-By: GH:jaraco
1 parent 302cf35 commit 1cf8424

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Lib/test/test_importlib/test_metadata_api.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import unittest
44
import warnings
55
import importlib
6+
import contextlib
67

78
from . import fixtures
89
from importlib.metadata import (
@@ -17,6 +18,13 @@
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+
2028
class 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', ()) == ()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In importlib.metadata tests, override warnings behavior under expected
2+
DeprecationWarnings (importlib_metadata 4.6.3).

0 commit comments

Comments
 (0)