diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2021-07-31 13:08:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-31 13:08:13 (GMT) |
commit | 1cf8424a62db38a041d421a46618e025bbb87f89 (patch) | |
tree | d7c427fb739b4225729f1165ea11da2ebf88d485 /Lib/test/test_importlib | |
parent | 302cf3550514b174b51b8c24d6e16cb47dc61755 (diff) | |
download | cpython-1cf8424a62db38a041d421a46618e025bbb87f89.zip cpython-1cf8424a62db38a041d421a46618e025bbb87f89.tar.gz cpython-1cf8424a62db38a041d421a46618e025bbb87f89.tar.bz2 |
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
Diffstat (limited to 'Lib/test/test_importlib')
-rw-r--r-- | Lib/test/test_importlib/test_metadata_api.py | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/Lib/test/test_importlib/test_metadata_api.py b/Lib/test/test_importlib/test_metadata_api.py index 2bfc44b..dc9c234 100644 --- a/Lib/test/test_importlib/test_metadata_api.py +++ b/Lib/test/test_importlib/test_metadata_api.py @@ -3,6 +3,7 @@ import textwrap import unittest import warnings import importlib +import contextlib from . import fixtures from importlib.metadata import ( @@ -17,6 +18,13 @@ 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, @@ -118,8 +126,7 @@ class APITests( # 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 @@ -138,8 +145,7 @@ class APITests( 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 @@ -151,7 +157,7 @@ class APITests( # 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): @@ -161,7 +167,7 @@ class APITests( # 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', ()) == () |