Skip to content

Commit c0d525e

Browse files
committed
config: expose PytestPluginManager for typing purposes
This type is used in hooks and transitively through `Config`.
1 parent 88d84a5 commit c0d525e

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

changelog/7469.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The newly-exported types are:
88
- ``pytest.MarkGenerator`` for the :class:`pytest.mark <pytest.MarkGenerator>` singleton.
99
- ``pytest.Metafunc`` for the :class:`metafunc <pytest.MarkGenerator>` argument to the :func:`pytest_generate_tests <pytest.hookspec.pytest_generate_tests>` hook.
1010
- ``pytest.CallInfo`` for the :class:`CallInfo <pytest.CallInfo>` type passed to various hooks.
11+
- ``pytest.PytestPluginManager`` for :class:`PytestPluginManager <pytest.PytestPluginManager>`.
1112
- ``pytest.ExceptionInfo`` for the :class:`ExceptionInfo <pytest.ExceptionInfo>` type returned from :func:`pytest.raises` and passed to various hooks.
1213

1314
Constructing them directly is not supported; they are only meant for use in type annotations.

doc/en/reference/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ Parser
896896
PytestPluginManager
897897
~~~~~~~~~~~~~~~~~~~
898898

899-
.. autoclass:: _pytest.config.PytestPluginManager()
899+
.. autoclass:: pytest.PytestPluginManager()
900900
:members:
901901
:undoc-members:
902902
:inherited-members:

src/_pytest/config/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def get_config(
290290

291291
def get_plugin_manager() -> "PytestPluginManager":
292292
"""Obtain a new instance of the
293-
:py:class:`_pytest.config.PytestPluginManager`, with default plugins
293+
:py:class:`pytest.PytestPluginManager`, with default plugins
294294
already loaded.
295295
296296
This function can be used by integration with other tools, like hooking
@@ -632,6 +632,7 @@ def _check_non_top_pytest_plugins(
632632
def consider_preparse(
633633
self, args: Sequence[str], *, exclude_only: bool = False
634634
) -> None:
635+
""":meta private:"""
635636
i = 0
636637
n = len(args)
637638
while i < n:
@@ -653,6 +654,7 @@ def consider_preparse(
653654
self.consider_pluginarg(parg)
654655

655656
def consider_pluginarg(self, arg: str) -> None:
657+
""":meta private:"""
656658
if arg.startswith("no:"):
657659
name = arg[3:]
658660
if name in essential_plugins:
@@ -678,12 +680,15 @@ def consider_pluginarg(self, arg: str) -> None:
678680
self.import_plugin(arg, consider_entry_points=True)
679681

680682
def consider_conftest(self, conftestmodule: types.ModuleType) -> None:
683+
""":meta private:"""
681684
self.register(conftestmodule, name=conftestmodule.__file__)
682685

683686
def consider_env(self) -> None:
687+
""":meta private:"""
684688
self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS"))
685689

686690
def consider_module(self, mod: types.ModuleType) -> None:
691+
""":meta private:"""
687692
self._import_plugin_specs(getattr(mod, "pytest_plugins", []))
688693

689694
def _import_plugin_specs(

src/_pytest/hookspec.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def pytest_addhooks(pluginmanager: "PytestPluginManager") -> None:
5656
"""Called at plugin registration time to allow adding new hooks via a call to
5757
``pluginmanager.add_hookspecs(module_or_class, prefix)``.
5858
59-
:param _pytest.config.PytestPluginManager pluginmanager: pytest plugin manager.
59+
:param pytest.PytestPluginManager pluginmanager: The pytest plugin manager.
6060
6161
.. note::
6262
This hook is incompatible with ``hookwrapper=True``.
@@ -70,7 +70,7 @@ def pytest_plugin_registered(
7070
"""A new pytest plugin got registered.
7171
7272
:param plugin: The plugin module or instance.
73-
:param _pytest.config.PytestPluginManager manager: pytest plugin manager.
73+
:param pytest.PytestPluginManager manager: pytest plugin manager.
7474
7575
.. note::
7676
This hook is incompatible with ``hookwrapper=True``.
@@ -94,8 +94,8 @@ def pytest_addoption(parser: "Parser", pluginmanager: "PytestPluginManager") ->
9494
To add ini-file values call :py:func:`parser.addini(...)
9595
<_pytest.config.argparsing.Parser.addini>`.
9696
97-
:param _pytest.config.PytestPluginManager pluginmanager:
98-
pytest plugin manager, which can be used to install :py:func:`hookspec`'s
97+
:param pytest.PytestPluginManager pluginmanager:
98+
The pytest plugin manager, which can be used to install :py:func:`hookspec`'s
9999
or :py:func:`hookimpl`'s and allow one plugin to call another plugin's hooks
100100
to change how command line options are added.
101101
@@ -152,7 +152,7 @@ def pytest_cmdline_parse(
152152
``plugins`` arg when using `pytest.main`_ to perform an in-process
153153
test run.
154154
155-
:param _pytest.config.PytestPluginManager pluginmanager: Pytest plugin manager.
155+
:param pytest.PytestPluginManager pluginmanager: The pytest plugin manager.
156156
:param List[str] args: List of arguments passed on the command line.
157157
"""
158158

src/pytest/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from _pytest.config import hookimpl
1414
from _pytest.config import hookspec
1515
from _pytest.config import main
16+
from _pytest.config import PytestPluginManager
1617
from _pytest.config import UsageError
1718
from _pytest.debugging import pytestPDB as __pytestPDB
1819
from _pytest.fixtures import _fillfuncargs
@@ -114,6 +115,7 @@
114115
"PytestDeprecationWarning",
115116
"PytestExperimentalApiWarning",
116117
"Pytester",
118+
"PytestPluginManager",
117119
"PytestUnhandledCoroutineWarning",
118120
"PytestUnhandledThreadExceptionWarning",
119121
"PytestUnknownMarkWarning",

0 commit comments

Comments
 (0)