Skip to content

Commit

Permalink
Merge pull request #333 from python/bpo-44784/actually-suppress-excep…
Browse files Browse the repository at this point in the history
…tions

Alter warnings filter for known deprecations, allowing test suite to pass.
  • Loading branch information
jaraco authored Jul 31, 2021
2 parents 596155c + 45722b7 commit 5583567
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v4.6.2
======

* bpo-44784: Avoid errors in test suite when
DeprecationWarnings are treated as errors.

v4.6.1
======

Expand Down
16 changes: 12 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
import warnings
import importlib
import contextlib

from . import fixtures
from importlib_metadata import (
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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):
Expand All @@ -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', ()) == ()
Expand Down

0 comments on commit 5583567

Please sign in to comment.