-
-
Notifications
You must be signed in to change notification settings - Fork 94
bpo-44451: Reset DeprecationWarning filters in test_api.test_entry_points_by_index #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Remove SelectableGroups deprecation exception for flake8.
…ints_by_index
This avoids the following error in CPython tests if DeprecationWarnings are ignored.
======================================================================
ERROR: test_entry_points_by_index (test.test_importlib.test_metadata_api.APITests)
Prior versions of Distribution.entry_points would return a
----------------------------------------------------------------------
Traceback (most recent call last):
File "/builddir/build/BUILD/Python-3.10.0b3/Lib/test/test_importlib/test_metadata_api.py", line 145, in test_entry_points_by_index
expected = next(iter(caught))
StopIteration
----------------------------------------------------------------------
Ran 1402 tests in 2.125s
FAILED (errors=1, skipped=18, expected failures=1)
|
Thanks for bringing this report and PR here. As I investigated and thought about it some more, I realized there was a deviation in how the deprecation warnings were being filtered in CPython versus here, a variance I introduced in 05e3288 (cpython branch only). There are a couple of ways I imagine we can handle this. One could be to repeat the previous approach and apply this change to the cpython branch only. Another could be to apply both changes here in the main branch, but that would lead to unneeded and unused code (that could be later removed). A third approach I considered is to extract a function that captures the scope and purpose of this variance, something like: diff --git a/tests/test_api.py b/tests/test_api.py
index 544ab7f4af4..0f51d6cb8d9 100644
--- a/tests/test_api.py
+++ b/tests/test_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,22 @@ from importlib_metadata import (
)
+@contextlib.contextmanager
+def catch_warnings():
+ """
+ Catch and record warnings in a context manager.
+
+ When on CPython, ensure that DeprecationWarnings manifest
+ using default settings (not suppressed).
+
+ Ref bpo-44451.
+ """
+ with warnings.catch_warnings(record=True) as caught:
+ if __name__.startswith('test.test_importlib.'):
+ warnings.filterwarnings("default", category=DeprecationWarning)
+ yield caught
+
+
class APITests(
fixtures.EggInfoPkg,
fixtures.DistInfoPkg,
@@ -122,7 +139,7 @@ class APITests(
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 catch_warnings() as caught:
eps = dict(entry_points(group='entries'))
assert 'main' in eps
@@ -141,8 +158,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 catch_warnings() as caught:
eps[0]
# check warningThis approach would be easier to extend to other cases where it's necessary. I'm not sure it's worth the mess/hassle. I think I'm leaning toward option 1. |
|
Weird that Github shows a merge conflict: Because I'm able to merge the change using the Git client without any concern. I suspect something about the Github git client doesn't understand the rename. So I'll push that merge commit and that will close this PR. |

This avoids the following error in CPython tests if DeprecationWarnings are ignored.