Skip to content

Commit 45722b7

Browse files
committed
Alter warnings filter for known deprecations, allowing test suite to pass.
1 parent 596155c commit 45722b7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

CHANGES.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v4.6.2
2+
======
3+
4+
* bpo-44784: Avoid errors in test suite when
5+
DeprecationWarnings are treated as errors.
6+
17
v4.6.1
28
======
39

tests/test_api.py

Lines changed: 12 additions & 4 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,
@@ -122,7 +130,7 @@ def test_entry_points_dict_construction(self):
122130
allowed casting those lists into maps by name using ``dict()``.
123131
Capture this now deprecated use-case.
124132
"""
125-
with warnings.catch_warnings(record=True) as caught:
133+
with suppress_known_deprecation() as caught:
126134
eps = dict(entry_points(group='entries'))
127135

128136
assert 'main' in eps
@@ -141,7 +149,7 @@ def test_entry_points_by_index(self):
141149
See python/importlib_metadata#300 and bpo-44246.
142150
"""
143151
eps = distribution('distinfo-pkg').entry_points
144-
with warnings.catch_warnings(record=True) as caught:
152+
with suppress_known_deprecation() as caught:
145153
eps[0]
146154

147155
# check warning
@@ -155,7 +163,7 @@ def test_entry_points_groups_getitem(self):
155163
that callers using '.__getitem__()' are supported but warned to
156164
migrate.
157165
"""
158-
with warnings.catch_warnings(record=True):
166+
with suppress_known_deprecation():
159167
entry_points()['entries'] == entry_points(group='entries')
160168

161169
with self.assertRaises(KeyError):
@@ -167,7 +175,7 @@ def test_entry_points_groups_get(self):
167175
that callers using '.get()' are supported but warned to
168176
migrate.
169177
"""
170-
with warnings.catch_warnings(record=True):
178+
with suppress_known_deprecation():
171179
entry_points().get('missing', 'default') == 'default'
172180
entry_points().get('entries', 'default') == entry_points()['entries']
173181
entry_points().get('missing', ()) == ()

0 commit comments

Comments
 (0)