import unittest
import warnings
import importlib
+import contextlib
from . import fixtures
from importlib.metadata import (
)
+@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,
# Prior versions of entry_points() returned simple lists and
# allowed casting those lists into maps by name using ``dict()``.
# Capture this now deprecated use-case.
- with warnings.catch_warnings(record=True) as caught:
- warnings.filterwarnings("default", category=DeprecationWarning)
+ with suppress_known_deprecation() as caught:
eps = dict(entry_points(group='entries'))
assert 'main' in eps
See python/importlib_metadata#300 and bpo-44246.
"""
eps = distribution('distinfo-pkg').entry_points
- with warnings.catch_warnings(record=True) as caught:
- warnings.filterwarnings("default", category=DeprecationWarning)
+ with suppress_known_deprecation() as caught:
eps[0]
# check warning
# Prior versions of entry_points() returned a dict. Ensure
# 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):
# Prior versions of entry_points() returned a dict. Ensure
# 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', ()) == ()