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 18, 2024
1 parent fe4961a commit a604ff0
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 21 deletions.
6 changes: 3 additions & 3 deletions doc/en/example/simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ the command line arguments before they get processed:

.. code-block:: python
# setuptools plugin
# installable external plugin
import sys
Expand Down Expand Up @@ -1073,8 +1073,8 @@ Instead of freezing the pytest runner as a separate executable, you can make
your frozen program work as the pytest runner by some clever
argument handling during program startup. This allows you to
have a single executable, which is usually more convenient.
Please note that the mechanism for plugin discovery used by pytest
(setuptools entry points) doesn't work with frozen executables so pytest
Please note that the mechanism for plugin discovery used by pytest (`entry points
<pip-installable plugins>`_) doesn't work with frozen executables so pytest
can't find any third party plugins automatically. To include third party plugins
like ``pytest-timeout`` they must be imported explicitly and passed on to pytest.main.

Expand Down
2 changes: 1 addition & 1 deletion doc/en/how-to/fixtures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ The same applies for the test folder level obviously.
Using fixtures from other projects
----------------------------------

Usually projects that provide pytest support will use :ref:`entry points <setuptools entry points>`,
Usually projects that provide pytest support will use :ref:`entry points <pip-installable plugins>`,
so just installing those projects into an environment will make those fixtures available for use.

In case you want to use fixtures from a project that does not use entry points, you can
Expand Down
2 changes: 1 addition & 1 deletion doc/en/how-to/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ You can early-load plugins (internal and external) explicitly in the command-lin
The option receives a ``name`` parameter, which can be:

* A full module dotted name, for example ``myproject.plugins``. This dotted name must be importable.
* The entry-point name of a plugin. This is the name passed to ``setuptools`` when the plugin is
* The entry-point name of a plugin. This is the name passed to ``importlib`` when the plugin is
registered. For example to early-load the :pypi:`pytest-cov` plugin you can use::

pytest -p pytest_cov
Expand Down
15 changes: 9 additions & 6 deletions doc/en/how-to/writing_plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ reporting by calling :ref:`well specified hooks <hook-reference>` of the followi

* builtin plugins: loaded from pytest's internal ``_pytest`` directory.

* :ref:`external plugins <extplugins>`: modules discovered through
`setuptools entry points`_
* :ref:`external plugins <extplugins>`: installed third-party modules discovered through
`entry points <pip-installable plugins>`_ in their packaging metadata

* `conftest.py plugins`_: modules auto-discovered in test directories

Expand All @@ -42,7 +42,8 @@ Plugin discovery order at tool startup
3. by scanning the command line for the ``-p name`` option
and loading the specified plugin. This happens before normal command-line parsing.

4. by loading all plugins registered through `setuptools entry points`_.
4. by loading all plugins registered through installed third-party package
`entry points <pip-installable plugins>`_.

5. by loading all plugins specified through the :envvar:`PYTEST_PLUGINS` environment variable.

Expand Down Expand Up @@ -142,7 +143,8 @@ Making your plugin installable by others
If you want to make your plugin externally available, you
may define a so-called entry point for your distribution so
that ``pytest`` finds your plugin module. Entry points are
a feature that is provided by :std:doc:`setuptools <setuptools:index>`.
a feature that is provided by :std:doc:`packaging tools
<packaging:specifications/entry-points>`.

pytest looks up the ``pytest11`` entrypoint to discover its
plugins, thus you can make your plugin available by defining
Expand Down Expand Up @@ -265,8 +267,9 @@ of the variable will also be loaded as plugins, and so on.
tests root directory is deprecated, and will raise a warning.

This mechanism makes it easy to share fixtures within applications or even
external applications without the need to create external plugins using
the ``setuptools``'s entry point technique.
external applications without the need to create external plugins using the
:std:doc:`entry point packaging metadata <guides/creating-and-discovering-plugins>`
technique.

Plugins imported by :globalvar:`pytest_plugins` will also automatically be marked
for assertion rewriting (see :func:`pytest.register_assert_rewrite`).
Expand Down
2 changes: 1 addition & 1 deletion doc/en/reference/customize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ and can also be used to hold pytest configuration if they have a ``[pytest]`` se
setup.cfg
~~~~~~~~~

``setup.cfg`` files are general purpose configuration files, used originally by ``distutils`` (now deprecated) and `setuptools <https://setuptools.pypa.io/en/latest/userguide/declarative_config.html>`__, and can also be used to hold pytest configuration
``setup.cfg`` files are general purpose configuration files, used originally by ``distutils`` (now deprecated) and :std:doc:`setuptools <setuptools:userguide/declarative_config>`, and can also be used to hold pytest configuration
if they have a ``[tool:pytest]`` section.

.. code-block:: ini
Expand Down
7 changes: 4 additions & 3 deletions doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ Reference to all hooks which can be implemented by :ref:`conftest.py files <loca
Bootstrapping hooks
~~~~~~~~~~~~~~~~~~~

Bootstrapping hooks called for plugins registered early enough (internal and setuptools plugins).
Bootstrapping hooks called for plugins registered early enough (internal and third-party plugins).

.. hook:: pytest_load_initial_conftests
.. autofunction:: pytest_load_initial_conftests
Expand Down Expand Up @@ -1147,8 +1147,9 @@ When set, pytest will print tracing and debug information.

.. envvar:: PYTEST_DISABLE_PLUGIN_AUTOLOAD

When set, disables plugin auto-loading through setuptools entrypoints. Only explicitly specified plugins will be
loaded.
When set, disables plugin auto-loading through :std:doc:`entry point packaging
metadata <guides/creating-and-discovering-plugins>`. Only explicitly specified
plugins will be loaded.

.. envvar:: PYTEST_PLUGINS

Expand Down
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("registered third-party plugins:")
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(
["*registered third-party plugins:", "*at*"]
)


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

0 comments on commit a604ff0

Please sign in to comment.