Skip to content

Reintroduce get_plugin_manager() for backward-compatibility #787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry i didn't say this earlier but i think we don't need to bother with deprecating it. @RonnyPfannschmidt , do you insist to deprecate it? I think it's ok to offer a method for IDEs and others to get a plugin manager instance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should just keep this around and remove the warning... waiting for @RonnyPfannschmidt's take on it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm wondering more about having a pytest-controller package,
that would support running py.test slave processes in various configurations

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting idea, but certainly out of the scope of this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's strike the deprecation and rather document get_plugin_manager() as official API (in plugins.txt i guess)


def _prepareconfig(args=None, plugins=None):
if args is None:
args = sys.argv[1:]
Expand Down Expand Up @@ -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 = []
Expand All @@ -135,6 +154,11 @@ def __init__(self):
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 "
Expand Down
10 changes: 10 additions & 0 deletions doc/en/writing_plugins.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,12 @@ def test_doctest_id(self, testdir):
"*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
Expand Down