Skip to content

Commit

Permalink
test_pluginmanager: use pluggy.manager.metadata
Browse files Browse the repository at this point in the history
This has the version switch in a central place only once.

Ref: https://github.com/pytest-dev/pluggy/pull/223/files#r315505111
  • Loading branch information
blueyed committed Aug 22, 2019
1 parent a1c6c35 commit 12133da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/pluggy/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import warnings

if sys.version_info >= (3, 8):
from importlib import metadata
from importlib import metadata as importlib_metadata
else:
import importlib_metadata as metadata
import importlib_metadata


def _warn_for_function(warning, function):
Expand Down Expand Up @@ -283,7 +283,7 @@ def load_setuptools_entrypoints(self, group, name=None):
:return: return the number of loaded plugins by this call.
"""
count = 0
for dist in metadata.distributions():
for dist in importlib_metadata.distributions():
for ep in dist.entry_points:
if (
ep.group != group
Expand Down
9 changes: 2 additions & 7 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
``PluginManager`` unit and public API testing.
"""
import pytest
import sys
import types

from pluggy import (
Expand All @@ -12,11 +11,7 @@
HookimplMarker,
HookspecMarker,
)

if sys.version_info >= (3, 8):
from importlib import metadata
else:
import importlib_metadata as metadata
from pluggy.manager import importlib_metadata


hookspec = HookspecMarker("example")
Expand Down Expand Up @@ -472,7 +467,7 @@ class Distribution(object):
def my_distributions():
return (dist,)

monkeypatch.setattr(metadata, "distributions", my_distributions)
monkeypatch.setattr(importlib_metadata, "distributions", my_distributions)
num = pm.load_setuptools_entrypoints("hello")
assert num == 1
plugin = pm.get_plugin("myname")
Expand Down

0 comments on commit 12133da

Please sign in to comment.