diff --git a/CHANGES.rst b/CHANGES.rst index 8829c3eb..d6cda8bc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,9 @@ +v4.6.2 +====== + +* bpo-44784: Avoid errors in test suite when + DeprecationWarnings are treated as errors. + v4.6.1 ====== diff --git a/tests/test_api.py b/tests/test_api.py index 819d4841..7ebcc1d8 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -3,6 +3,7 @@ import unittest import warnings import importlib +import contextlib from . import fixtures from importlib_metadata import ( @@ -17,6 +18,13 @@ ) +@contextlib.contextmanager +def suppress_known_deprecation(): + with warnings.catch_warnings(record=True) as ctx: + warnings.simplefilter('default') + yield ctx + + class APITests( fixtures.EggInfoPkg, fixtures.DistInfoPkg, @@ -122,7 +130,7 @@ def test_entry_points_dict_construction(self): allowed casting those lists into maps by name using ``dict()``. Capture this now deprecated use-case. """ - with warnings.catch_warnings(record=True) as caught: + with suppress_known_deprecation() as caught: eps = dict(entry_points(group='entries')) assert 'main' in eps @@ -141,7 +149,7 @@ def test_entry_points_by_index(self): See python/importlib_metadata#300 and bpo-44246. """ eps = distribution('distinfo-pkg').entry_points - with warnings.catch_warnings(record=True) as caught: + with suppress_known_deprecation() as caught: eps[0] # check warning @@ -155,7 +163,7 @@ def test_entry_points_groups_getitem(self): that callers using '.__getitem__()' are supported but warned to migrate. """ - with warnings.catch_warnings(record=True): + with suppress_known_deprecation(): entry_points()['entries'] == entry_points(group='entries') with self.assertRaises(KeyError): @@ -167,7 +175,7 @@ def test_entry_points_groups_get(self): that callers using '.get()' are supported but warned to migrate. """ - with warnings.catch_warnings(record=True): + with suppress_known_deprecation(): entry_points().get('missing', 'default') == 'default' entry_points().get('entries', 'default') == entry_points()['entries'] entry_points().get('missing', ()) == ()