Skip to content

Commit ae4c8b8

Browse files
committed
Merge pull request #787 from pytest-dev/pluggy-bc-fix
Reintroduce get_plugin_manager() for backward-compatibility
2 parents d70a311 + 3c2fd83 commit ae4c8b8

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

_pytest/config.py

+24
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ def get_config():
8282
pluginmanager.import_plugin(spec)
8383
return config
8484

85+
def get_plugin_manager():
86+
"""
87+
Obtain a new instance of the
88+
:py:class:`_pytest.config.PytestPluginManager`, with default plugins
89+
already loaded.
90+
91+
This function can be used by integration with other tools, like hooking
92+
into pytest to run tests into an IDE.
93+
"""
94+
return get_config().pluginmanager
95+
8596
def _prepareconfig(args=None, plugins=None):
8697
if args is None:
8798
args = sys.argv[1:]
@@ -111,6 +122,14 @@ def exclude_pytest_names(name):
111122

112123

113124
class PytestPluginManager(PluginManager):
125+
"""
126+
Overwrites :py:class:`pluggy.PluginManager` to add pytest-specific
127+
functionality:
128+
129+
* loading plugins from the command line, ``PYTEST_PLUGIN`` env variable and
130+
``pytest_plugins`` global variables found in plugins being loaded;
131+
* ``conftest.py`` loading during start-up;
132+
"""
114133
def __init__(self):
115134
super(PytestPluginManager, self).__init__("pytest", implprefix="pytest_")
116135
self._warnings = []
@@ -135,6 +154,11 @@ def __init__(self):
135154
self.enable_tracing()
136155

137156
def addhooks(self, module_or_class):
157+
"""
158+
.. deprecated:: 2.8
159+
160+
Use :py:meth:`pluggy.PluginManager.add_hookspecs` instead.
161+
"""
138162
warning = dict(code="I2",
139163
fslocation=py.code.getfslineno(sys._getframe(1)),
140164
message="use pluginmanager.add_hookspecs instead of "

doc/en/writing_plugins.txt

+10
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,16 @@ Reference of objects involved in hooks
531531
.. autoclass:: _pytest.core.CallOutcome()
532532
:members:
533533

534+
.. autofunction:: _pytest.config.get_plugin_manager()
535+
536+
.. autoclass:: _pytest.config.PytestPluginManager()
537+
:members:
538+
:undoc-members:
539+
:show-inheritance:
540+
541+
.. autoclass:: pluggy.PluginManager()
542+
:members:
543+
534544
.. currentmodule:: _pytest.pytester
535545

536546
.. autoclass:: Testdir()

testing/acceptance_test.py

+6
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,12 @@ def test_doctest_id(self, testdir):
564564
"*1 failed*",
565565
])
566566

567+
def test_core_backward_compatibility(self):
568+
"""Test backward compatibility for get_plugin_manager function. See #787."""
569+
import _pytest.config
570+
assert type(_pytest.config.get_plugin_manager()) is _pytest.config.PytestPluginManager
571+
572+
567573
class TestDurations:
568574
source = """
569575
import time

0 commit comments

Comments
 (0)