Merge pull request #787 from pytest-dev/pluggy-bc-fix

Reintroduce get_plugin_manager() for backward-compatibility
This commit is contained in:
Bruno Oliveira 2015-07-08 19:28:01 -03:00
commit ae4c8b8635
3 changed files with 40 additions and 0 deletions

View File

@ -82,6 +82,17 @@ def get_config():
pluginmanager.import_plugin(spec)
return config
def get_plugin_manager():
"""
Obtain a new instance of the
:py:class:`_pytest.config.PytestPluginManager`, with default plugins
already loaded.
This function can be used by integration with other tools, like hooking
into pytest to run tests into an IDE.
"""
return get_config().pluginmanager
def _prepareconfig(args=None, plugins=None):
if args is None:
args = sys.argv[1:]
@ -111,6 +122,14 @@ def exclude_pytest_names(name):
class PytestPluginManager(PluginManager):
"""
Overwrites :py:class:`pluggy.PluginManager` to add pytest-specific
functionality:
* loading plugins from the command line, ``PYTEST_PLUGIN`` env variable and
``pytest_plugins`` global variables found in plugins being loaded;
* ``conftest.py`` loading during start-up;
"""
def __init__(self):
super(PytestPluginManager, self).__init__("pytest", implprefix="pytest_")
self._warnings = []
@ -135,6 +154,11 @@ class PytestPluginManager(PluginManager):
self.enable_tracing()
def addhooks(self, module_or_class):
"""
.. deprecated:: 2.8
Use :py:meth:`pluggy.PluginManager.add_hookspecs` instead.
"""
warning = dict(code="I2",
fslocation=py.code.getfslineno(sys._getframe(1)),
message="use pluginmanager.add_hookspecs instead of "

View File

@ -531,6 +531,16 @@ Reference of objects involved in hooks
.. autoclass:: _pytest.core.CallOutcome()
:members:
.. autofunction:: _pytest.config.get_plugin_manager()
.. autoclass:: _pytest.config.PytestPluginManager()
:members:
:undoc-members:
:show-inheritance:
.. autoclass:: pluggy.PluginManager()
:members:
.. currentmodule:: _pytest.pytester
.. autoclass:: Testdir()

View File

@ -564,6 +564,12 @@ class TestInvocationVariants:
"*1 failed*",
])
def test_core_backward_compatibility(self):
"""Test backward compatibility for get_plugin_manager function. See #787."""
import _pytest.config
assert type(_pytest.config.get_plugin_manager()) is _pytest.config.PytestPluginManager
class TestDurations:
source = """
import time