remove _do_register indirection between PluginManager and PytestPluginManager
--HG-- branch : more_plugin
This commit is contained in:
		
							parent
							
								
									f41528433b
								
							
						
					
					
						commit
						bbbb6dc2e3
					
				|  | @ -119,16 +119,13 @@ class PytestPluginManager(PluginManager): | ||||||
| 
 | 
 | ||||||
|     def register(self, plugin, name=None, conftest=False): |     def register(self, plugin, name=None, conftest=False): | ||||||
|         ret = super(PytestPluginManager, self).register(plugin, name) |         ret = super(PytestPluginManager, self).register(plugin, name) | ||||||
|         if ret and not conftest: |         if ret: | ||||||
|             self._globalplugins.append(plugin) |             if not conftest: | ||||||
|  |                 self._globalplugins.append(plugin) | ||||||
|  |             if hasattr(self, "config"): | ||||||
|  |                 self.config._register_plugin(plugin, name) | ||||||
|         return ret |         return ret | ||||||
| 
 | 
 | ||||||
|     def _do_register(self, plugin, name): |  | ||||||
|         # called from core PluginManager class |  | ||||||
|         if hasattr(self, "config"): |  | ||||||
|             self.config._register_plugin(plugin, name) |  | ||||||
|         return super(PytestPluginManager, self)._do_register(plugin, name) |  | ||||||
| 
 |  | ||||||
|     def unregister(self, plugin): |     def unregister(self, plugin): | ||||||
|         super(PytestPluginManager, self).unregister(plugin) |         super(PytestPluginManager, self).unregister(plugin) | ||||||
|         try: |         try: | ||||||
|  | @ -710,8 +707,7 @@ class Config(object): | ||||||
| 
 | 
 | ||||||
|     def _register_plugin(self, plugin, name): |     def _register_plugin(self, plugin, name): | ||||||
|         call_plugin = self.pluginmanager.call_plugin |         call_plugin = self.pluginmanager.call_plugin | ||||||
|         call_plugin(plugin, "pytest_addhooks", |         call_plugin(plugin, "pytest_addhooks", {'pluginmanager': self.pluginmanager}) | ||||||
|                     {'pluginmanager': self.pluginmanager}) |  | ||||||
|         self.hook.pytest_plugin_registered(plugin=plugin, |         self.hook.pytest_plugin_registered(plugin=plugin, | ||||||
|                                            manager=self.pluginmanager) |                                            manager=self.pluginmanager) | ||||||
|         dic = call_plugin(plugin, "pytest_namespace", {}) or {} |         dic = call_plugin(plugin, "pytest_namespace", {}) or {} | ||||||
|  |  | ||||||
|  | @ -201,10 +201,6 @@ class PluginManager(object): | ||||||
|             raise ValueError("Plugin already registered: %s=%s\n%s" %( |             raise ValueError("Plugin already registered: %s=%s\n%s" %( | ||||||
|                               name, plugin, self._name2plugin)) |                               name, plugin, self._name2plugin)) | ||||||
|         #self.trace("registering", name, plugin) |         #self.trace("registering", name, plugin) | ||||||
|         # allow subclasses to intercept here by calling a helper |  | ||||||
|         return self._do_register(plugin, name) |  | ||||||
| 
 |  | ||||||
|     def _do_register(self, plugin, name): |  | ||||||
|         self._plugin2hookcallers[plugin] = self._scan_plugin(plugin) |         self._plugin2hookcallers[plugin] = self._scan_plugin(plugin) | ||||||
|         self._name2plugin[name] = plugin |         self._name2plugin[name] = plugin | ||||||
|         self._plugins.append(plugin) |         self._plugins.append(plugin) | ||||||
|  |  | ||||||
|  | @ -77,6 +77,7 @@ class TestPluginManager: | ||||||
|         #assert not pm._unverified_hooks |         #assert not pm._unverified_hooks | ||||||
|         assert pm.hook.he_method1(arg=1) == [2] |         assert pm.hook.he_method1(arg=1) == [2] | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| class TestAddMethodOrdering: | class TestAddMethodOrdering: | ||||||
|     @pytest.fixture |     @pytest.fixture | ||||||
|     def hc(self, pm): |     def hc(self, pm): | ||||||
|  | @ -283,24 +284,30 @@ class TestPytestPluginInteractions: | ||||||
|         pytestpm = get_plugin_manager()  # fully initialized with plugins |         pytestpm = get_plugin_manager()  # fully initialized with plugins | ||||||
|         saveindent = [] |         saveindent = [] | ||||||
|         class api1: |         class api1: | ||||||
|             x = 41 |  | ||||||
|             def pytest_plugin_registered(self, plugin): |             def pytest_plugin_registered(self, plugin): | ||||||
|                 saveindent.append(pytestpm.trace.root.indent) |                 saveindent.append(pytestpm.trace.root.indent) | ||||||
|                 raise ValueError(42) |         class api2: | ||||||
|  |             def pytest_plugin_registered(self, plugin): | ||||||
|  |                 saveindent.append(pytestpm.trace.root.indent) | ||||||
|  |                 raise ValueError() | ||||||
|         l = [] |         l = [] | ||||||
|         pytestpm.set_tracing(l.append) |         undo = pytestpm.set_tracing(l.append) | ||||||
|         indent = pytestpm.trace.root.indent |         try: | ||||||
|         p = api1() |             indent = pytestpm.trace.root.indent | ||||||
|         pytestpm.register(p) |             p = api1() | ||||||
|  |             pytestpm.register(p) | ||||||
|  |             assert pytestpm.trace.root.indent == indent | ||||||
|  |             assert len(l) == 2 | ||||||
|  |             assert 'pytest_plugin_registered' in l[0] | ||||||
|  |             assert 'finish' in l[1] | ||||||
| 
 | 
 | ||||||
|         assert pytestpm.trace.root.indent == indent |             l[:] = [] | ||||||
|         assert len(l) == 2 |             with pytest.raises(ValueError): | ||||||
|         assert 'pytest_plugin_registered' in l[0] |                 pytestpm.register(api2()) | ||||||
|         assert 'finish' in l[1] |             assert pytestpm.trace.root.indent == indent | ||||||
|         with pytest.raises(ValueError): |             assert saveindent[0] > indent | ||||||
|             pytestpm.register(api1()) |         finally: | ||||||
|         assert pytestpm.trace.root.indent == indent |             undo() | ||||||
|         assert saveindent[0] > indent |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_namespace_has_default_and_env_plugins(testdir): | def test_namespace_has_default_and_env_plugins(testdir): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue