config: expose PytestPluginManager for typing purposes
This type is used in hooks and transitively through `Config`.
This commit is contained in:
parent
88d84a5791
commit
c0d525e44c
|
@ -8,6 +8,7 @@ The newly-exported types are:
|
||||||
- ``pytest.MarkGenerator`` for the :class:`pytest.mark <pytest.MarkGenerator>` singleton.
|
- ``pytest.MarkGenerator`` for the :class:`pytest.mark <pytest.MarkGenerator>` singleton.
|
||||||
- ``pytest.Metafunc`` for the :class:`metafunc <pytest.MarkGenerator>` argument to the :func:`pytest_generate_tests <pytest.hookspec.pytest_generate_tests>` hook.
|
- ``pytest.Metafunc`` for the :class:`metafunc <pytest.MarkGenerator>` argument to the :func:`pytest_generate_tests <pytest.hookspec.pytest_generate_tests>` hook.
|
||||||
- ``pytest.CallInfo`` for the :class:`CallInfo <pytest.CallInfo>` type passed to various hooks.
|
- ``pytest.CallInfo`` for the :class:`CallInfo <pytest.CallInfo>` type passed to various hooks.
|
||||||
|
- ``pytest.PytestPluginManager`` for :class:`PytestPluginManager <pytest.PytestPluginManager>`.
|
||||||
- ``pytest.ExceptionInfo`` for the :class:`ExceptionInfo <pytest.ExceptionInfo>` type returned from :func:`pytest.raises` and passed to various hooks.
|
- ``pytest.ExceptionInfo`` for the :class:`ExceptionInfo <pytest.ExceptionInfo>` type returned from :func:`pytest.raises` and passed to various hooks.
|
||||||
|
|
||||||
Constructing them directly is not supported; they are only meant for use in type annotations.
|
Constructing them directly is not supported; they are only meant for use in type annotations.
|
||||||
|
|
|
@ -896,7 +896,7 @@ Parser
|
||||||
PytestPluginManager
|
PytestPluginManager
|
||||||
~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
.. autoclass:: _pytest.config.PytestPluginManager()
|
.. autoclass:: pytest.PytestPluginManager()
|
||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:inherited-members:
|
:inherited-members:
|
||||||
|
|
|
@ -290,7 +290,7 @@ def get_config(
|
||||||
|
|
||||||
def get_plugin_manager() -> "PytestPluginManager":
|
def get_plugin_manager() -> "PytestPluginManager":
|
||||||
"""Obtain a new instance of the
|
"""Obtain a new instance of the
|
||||||
:py:class:`_pytest.config.PytestPluginManager`, with default plugins
|
:py:class:`pytest.PytestPluginManager`, with default plugins
|
||||||
already loaded.
|
already loaded.
|
||||||
|
|
||||||
This function can be used by integration with other tools, like hooking
|
This function can be used by integration with other tools, like hooking
|
||||||
|
@ -632,6 +632,7 @@ class PytestPluginManager(PluginManager):
|
||||||
def consider_preparse(
|
def consider_preparse(
|
||||||
self, args: Sequence[str], *, exclude_only: bool = False
|
self, args: Sequence[str], *, exclude_only: bool = False
|
||||||
) -> None:
|
) -> None:
|
||||||
|
""":meta private:"""
|
||||||
i = 0
|
i = 0
|
||||||
n = len(args)
|
n = len(args)
|
||||||
while i < n:
|
while i < n:
|
||||||
|
@ -653,6 +654,7 @@ class PytestPluginManager(PluginManager):
|
||||||
self.consider_pluginarg(parg)
|
self.consider_pluginarg(parg)
|
||||||
|
|
||||||
def consider_pluginarg(self, arg: str) -> None:
|
def consider_pluginarg(self, arg: str) -> None:
|
||||||
|
""":meta private:"""
|
||||||
if arg.startswith("no:"):
|
if arg.startswith("no:"):
|
||||||
name = arg[3:]
|
name = arg[3:]
|
||||||
if name in essential_plugins:
|
if name in essential_plugins:
|
||||||
|
@ -678,12 +680,15 @@ class PytestPluginManager(PluginManager):
|
||||||
self.import_plugin(arg, consider_entry_points=True)
|
self.import_plugin(arg, consider_entry_points=True)
|
||||||
|
|
||||||
def consider_conftest(self, conftestmodule: types.ModuleType) -> None:
|
def consider_conftest(self, conftestmodule: types.ModuleType) -> None:
|
||||||
|
""":meta private:"""
|
||||||
self.register(conftestmodule, name=conftestmodule.__file__)
|
self.register(conftestmodule, name=conftestmodule.__file__)
|
||||||
|
|
||||||
def consider_env(self) -> None:
|
def consider_env(self) -> None:
|
||||||
|
""":meta private:"""
|
||||||
self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS"))
|
self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS"))
|
||||||
|
|
||||||
def consider_module(self, mod: types.ModuleType) -> None:
|
def consider_module(self, mod: types.ModuleType) -> None:
|
||||||
|
""":meta private:"""
|
||||||
self._import_plugin_specs(getattr(mod, "pytest_plugins", []))
|
self._import_plugin_specs(getattr(mod, "pytest_plugins", []))
|
||||||
|
|
||||||
def _import_plugin_specs(
|
def _import_plugin_specs(
|
||||||
|
|
|
@ -56,7 +56,7 @@ def pytest_addhooks(pluginmanager: "PytestPluginManager") -> None:
|
||||||
"""Called at plugin registration time to allow adding new hooks via a call to
|
"""Called at plugin registration time to allow adding new hooks via a call to
|
||||||
``pluginmanager.add_hookspecs(module_or_class, prefix)``.
|
``pluginmanager.add_hookspecs(module_or_class, prefix)``.
|
||||||
|
|
||||||
:param _pytest.config.PytestPluginManager pluginmanager: pytest plugin manager.
|
:param pytest.PytestPluginManager pluginmanager: The pytest plugin manager.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
This hook is incompatible with ``hookwrapper=True``.
|
This hook is incompatible with ``hookwrapper=True``.
|
||||||
|
@ -70,7 +70,7 @@ def pytest_plugin_registered(
|
||||||
"""A new pytest plugin got registered.
|
"""A new pytest plugin got registered.
|
||||||
|
|
||||||
:param plugin: The plugin module or instance.
|
:param plugin: The plugin module or instance.
|
||||||
:param _pytest.config.PytestPluginManager manager: pytest plugin manager.
|
:param pytest.PytestPluginManager manager: pytest plugin manager.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
This hook is incompatible with ``hookwrapper=True``.
|
This hook is incompatible with ``hookwrapper=True``.
|
||||||
|
@ -94,8 +94,8 @@ def pytest_addoption(parser: "Parser", pluginmanager: "PytestPluginManager") ->
|
||||||
To add ini-file values call :py:func:`parser.addini(...)
|
To add ini-file values call :py:func:`parser.addini(...)
|
||||||
<_pytest.config.argparsing.Parser.addini>`.
|
<_pytest.config.argparsing.Parser.addini>`.
|
||||||
|
|
||||||
:param _pytest.config.PytestPluginManager pluginmanager:
|
:param pytest.PytestPluginManager pluginmanager:
|
||||||
pytest plugin manager, which can be used to install :py:func:`hookspec`'s
|
The pytest plugin manager, which can be used to install :py:func:`hookspec`'s
|
||||||
or :py:func:`hookimpl`'s and allow one plugin to call another plugin's hooks
|
or :py:func:`hookimpl`'s and allow one plugin to call another plugin's hooks
|
||||||
to change how command line options are added.
|
to change how command line options are added.
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ def pytest_cmdline_parse(
|
||||||
``plugins`` arg when using `pytest.main`_ to perform an in-process
|
``plugins`` arg when using `pytest.main`_ to perform an in-process
|
||||||
test run.
|
test run.
|
||||||
|
|
||||||
:param _pytest.config.PytestPluginManager pluginmanager: Pytest plugin manager.
|
:param pytest.PytestPluginManager pluginmanager: The pytest plugin manager.
|
||||||
:param List[str] args: List of arguments passed on the command line.
|
:param List[str] args: List of arguments passed on the command line.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ from _pytest.config import ExitCode
|
||||||
from _pytest.config import hookimpl
|
from _pytest.config import hookimpl
|
||||||
from _pytest.config import hookspec
|
from _pytest.config import hookspec
|
||||||
from _pytest.config import main
|
from _pytest.config import main
|
||||||
|
from _pytest.config import PytestPluginManager
|
||||||
from _pytest.config import UsageError
|
from _pytest.config import UsageError
|
||||||
from _pytest.debugging import pytestPDB as __pytestPDB
|
from _pytest.debugging import pytestPDB as __pytestPDB
|
||||||
from _pytest.fixtures import _fillfuncargs
|
from _pytest.fixtures import _fillfuncargs
|
||||||
|
@ -114,6 +115,7 @@ __all__ = [
|
||||||
"PytestDeprecationWarning",
|
"PytestDeprecationWarning",
|
||||||
"PytestExperimentalApiWarning",
|
"PytestExperimentalApiWarning",
|
||||||
"Pytester",
|
"Pytester",
|
||||||
|
"PytestPluginManager",
|
||||||
"PytestUnhandledCoroutineWarning",
|
"PytestUnhandledCoroutineWarning",
|
||||||
"PytestUnhandledThreadExceptionWarning",
|
"PytestUnhandledThreadExceptionWarning",
|
||||||
"PytestUnknownMarkWarning",
|
"PytestUnknownMarkWarning",
|
||||||
|
|
Loading…
Reference in New Issue