Mailing List Archive

bpo-44784: Apply changes from importlib_metadata 4.6.3 (GH-27508) (#27510)
https://github.com/python/cpython/commit/21d5897982698a461215203ab51f56ad05648001
commit: 21d5897982698a461215203ab51f56ad05648001
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
committer: jaraco <jaraco@jaraco.com>
date: 2021-07-31T23:01:38-04:00
summary:

bpo-44784: Apply changes from importlib_metadata 4.6.3 (GH-27508) (#27510)

Addressing issues with tests under error on warnings.

Automerge-Triggered-By: GH:jaraco
(cherry picked from commit 1cf8424a62db38a041d421a46618e025bbb87f89)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>

files:
A Misc/NEWS.d/next/Library/2021-07-31-08-45-31.bpo-44784.fIMIDS.rst
M Lib/test/test_importlib/test_metadata_api.py

diff --git a/Lib/test/test_importlib/test_metadata_api.py b/Lib/test/test_importlib/test_metadata_api.py
index 2bfc44b18eedb4..dc9c234d15b785 100644
--- a/Lib/test/test_importlib/test_metadata_api.py
+++ b/Lib/test/test_importlib/test_metadata_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,
@@ -118,8 +126,7 @@ def test_entry_points_dict_construction(self):
# 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 @@ 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:
- warnings.filterwarnings("default", category=DeprecationWarning)
+ with suppress_known_deprecation() as caught:
eps[0]

# check warning
@@ -151,7 +157,7 @@ def test_entry_points_groups_getitem(self):
# 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 @@ def test_entry_points_groups_get(self):
# 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', ()) == ()
diff --git a/Misc/NEWS.d/next/Library/2021-07-31-08-45-31.bpo-44784.fIMIDS.rst b/Misc/NEWS.d/next/Library/2021-07-31-08-45-31.bpo-44784.fIMIDS.rst
new file mode 100644
index 00000000000000..6ad10ef3f59805
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-07-31-08-45-31.bpo-44784.fIMIDS.rst
@@ -0,0 +1,2 @@
+In importlib.metadata tests, override warnings behavior under expected
+DeprecationWarnings (importlib_metadata 4.6.3).

_______________________________________________
Python-checkins mailing list
Python-checkins@python.org
https://mail.python.org/mailman/listinfo/python-checkins