Skip to content

Commit

Permalink
📝 Make "setuptools entrypoint" term generic
Browse files Browse the repository at this point in the history
This feature grew out of `setuptools` but the modern interface for
extracting this information from the distribution package metadata
is `importlib.metadata`. So the patch attempts to reflect this in
the documentation messaging.

Refs:
* https://docs.python.org/3/library/importlib.metadata.html#entry-points
* https://packaging.python.org/en/latest/guides/creating-and-discovering-plugins/#using-package-metadata
* https://packaging.python.org/en/latest/specifications/entry-points/#entry-points
  • Loading branch information
webknjaz committed Jun 17, 2024
1 parent fe4961a commit 851cf5a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,8 @@ def _mark_plugins_for_rewrite(self, hook) -> None:
self.pluginmanager.rewrite_hook = hook

if os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD"):
# We don't autoload from setuptools entry points, no need to continue.
# We don't autoload from distribution package entry points,
# no need to continue.
return

package_files = (
Expand Down Expand Up @@ -1381,8 +1382,8 @@ def _preparse(self, args: List[str], addopts: bool = True) -> None:
self._consider_importhook(args)
self.pluginmanager.consider_preparse(args, exclude_only=False)
if not os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD"):
# Don't autoload from setuptools entry point. Only explicitly specified
# plugins are going to be loaded.
# Don't autoload from distribution package entry point. Only
# explicitly specified plugins are going to be loaded.
self.pluginmanager.load_setuptools_entrypoints("pytest11")
self.pluginmanager.consider_env()

Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def getpluginversioninfo(config: Config) -> List[str]:
lines = []
plugininfo = config.pluginmanager.list_plugin_distinfo()
if plugininfo:
lines.append("setuptools registered plugins:")
lines.append("distribution package registered plugins:")

Check warning on line 246 in src/_pytest/helpconfig.py

View check run for this annotation

Codecov / codecov/patch

src/_pytest/helpconfig.py#L246

Added line #L246 was not covered by tests
for plugin, dist in plugininfo:
loc = getattr(plugin, "__file__", repr(plugin))
content = f"{dist.project_name}-{dist.version} at {loc}"
Expand Down
2 changes: 1 addition & 1 deletion testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_installed_plugin_rewrite(
) -> None:
monkeypatch.delenv("PYTEST_DISABLE_PLUGIN_AUTOLOAD", raising=False)
# Make sure the hook is installed early enough so that plugins
# installed via setuptools are rewritten.
# installed via distribution package are rewritten.
pytester.mkdir("hampkg")
contents = {
"hampkg/__init__.py": """\
Expand Down
4 changes: 3 additions & 1 deletion testing/test_helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def test_version_verbose(pytester: Pytester, pytestconfig, monkeypatch) -> None:
assert result.ret == 0
result.stdout.fnmatch_lines([f"*pytest*{pytest.__version__}*imported from*"])
if pytestconfig.pluginmanager.list_plugin_distinfo():
result.stdout.fnmatch_lines(["*setuptools registered plugins:", "*at*"])
result.stdout.fnmatch_lines(
["*distribution package registered plugins:", "*at*"]
)


def test_version_less_verbose(pytester: Pytester, pytestconfig, monkeypatch) -> None:
Expand Down

0 comments on commit 851cf5a

Please sign in to comment.