Skip to content

Commit 12133da

Browse files
committed
test_pluginmanager: use pluggy.manager.metadata
This has the version switch in a central place only once. Ref: https://github.com/pytest-dev/pluggy/pull/223/files#r315505111
1 parent a1c6c35 commit 12133da

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/pluggy/manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import warnings
66

77
if sys.version_info >= (3, 8):
8-
from importlib import metadata
8+
from importlib import metadata as importlib_metadata
99
else:
10-
import importlib_metadata as metadata
10+
import importlib_metadata
1111

1212

1313
def _warn_for_function(warning, function):
@@ -283,7 +283,7 @@ def load_setuptools_entrypoints(self, group, name=None):
283283
:return: return the number of loaded plugins by this call.
284284
"""
285285
count = 0
286-
for dist in metadata.distributions():
286+
for dist in importlib_metadata.distributions():
287287
for ep in dist.entry_points:
288288
if (
289289
ep.group != group

testing/test_pluginmanager.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
``PluginManager`` unit and public API testing.
33
"""
44
import pytest
5-
import sys
65
import types
76

87
from pluggy import (
@@ -12,11 +11,7 @@
1211
HookimplMarker,
1312
HookspecMarker,
1413
)
15-
16-
if sys.version_info >= (3, 8):
17-
from importlib import metadata
18-
else:
19-
import importlib_metadata as metadata
14+
from pluggy.manager import importlib_metadata
2015

2116

2217
hookspec = HookspecMarker("example")
@@ -472,7 +467,7 @@ class Distribution(object):
472467
def my_distributions():
473468
return (dist,)
474469

475-
monkeypatch.setattr(metadata, "distributions", my_distributions)
470+
monkeypatch.setattr(importlib_metadata, "distributions", my_distributions)
476471
num = pm.load_setuptools_entrypoints("hello")
477472
assert num == 1
478473
plugin = pm.get_plugin("myname")

0 commit comments

Comments
 (0)