Merge pull request #787 from pytest-dev/pluggy-bc-fix
Reintroduce get_plugin_manager() for backward-compatibility
This commit is contained in:
		
						commit
						ae4c8b8635
					
				|  | @ -82,6 +82,17 @@ def get_config(): | ||||||
|         pluginmanager.import_plugin(spec) |         pluginmanager.import_plugin(spec) | ||||||
|     return config |     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): | def _prepareconfig(args=None, plugins=None): | ||||||
|     if args is None: |     if args is None: | ||||||
|         args = sys.argv[1:] |         args = sys.argv[1:] | ||||||
|  | @ -111,6 +122,14 @@ def exclude_pytest_names(name): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class PytestPluginManager(PluginManager): | 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): |     def __init__(self): | ||||||
|         super(PytestPluginManager, self).__init__("pytest", implprefix="pytest_") |         super(PytestPluginManager, self).__init__("pytest", implprefix="pytest_") | ||||||
|         self._warnings = [] |         self._warnings = [] | ||||||
|  | @ -135,6 +154,11 @@ class PytestPluginManager(PluginManager): | ||||||
|             self.enable_tracing() |             self.enable_tracing() | ||||||
| 
 | 
 | ||||||
|     def addhooks(self, module_or_class): |     def addhooks(self, module_or_class): | ||||||
|  |         """ | ||||||
|  |         .. deprecated:: 2.8 | ||||||
|  | 
 | ||||||
|  |         Use :py:meth:`pluggy.PluginManager.add_hookspecs` instead. | ||||||
|  |         """ | ||||||
|         warning = dict(code="I2", |         warning = dict(code="I2", | ||||||
|                        fslocation=py.code.getfslineno(sys._getframe(1)), |                        fslocation=py.code.getfslineno(sys._getframe(1)), | ||||||
|                        message="use pluginmanager.add_hookspecs instead of " |                        message="use pluginmanager.add_hookspecs instead of " | ||||||
|  |  | ||||||
|  | @ -531,6 +531,16 @@ Reference of objects involved in hooks | ||||||
| .. autoclass:: _pytest.core.CallOutcome() | .. autoclass:: _pytest.core.CallOutcome() | ||||||
|     :members: |     :members: | ||||||
| 
 | 
 | ||||||
|  | .. autofunction:: _pytest.config.get_plugin_manager() | ||||||
|  | 
 | ||||||
|  | .. autoclass:: _pytest.config.PytestPluginManager() | ||||||
|  |     :members: | ||||||
|  |     :undoc-members: | ||||||
|  |     :show-inheritance: | ||||||
|  | 
 | ||||||
|  | .. autoclass:: pluggy.PluginManager() | ||||||
|  |     :members: | ||||||
|  | 
 | ||||||
| .. currentmodule:: _pytest.pytester | .. currentmodule:: _pytest.pytester | ||||||
| 
 | 
 | ||||||
| .. autoclass:: Testdir() | .. autoclass:: Testdir() | ||||||
|  |  | ||||||
|  | @ -564,6 +564,12 @@ class TestInvocationVariants: | ||||||
|             "*1 failed*", |             "*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: | class TestDurations: | ||||||
|     source = """ |     source = """ | ||||||
|         import time |         import time | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue