refine fromdictargs to avoid an uncessary re-setup of the pluginmanager
This commit is contained in:
		
							parent
							
								
									fad7bd4393
								
							
						
					
					
						commit
						03c314e3be
					
				|  | @ -516,7 +516,9 @@ class Config(object): | ||||||
|     @classmethod |     @classmethod | ||||||
|     def fromdictargs(cls, option_dict, args): |     def fromdictargs(cls, option_dict, args): | ||||||
|         """ constructor useable for subprocesses. """ |         """ constructor useable for subprocesses. """ | ||||||
|         config = cls(PluginManager(load=True)) |         from _pytest.core import get_plugin_manager | ||||||
|  |         pluginmanager = get_plugin_manager() | ||||||
|  |         config = cls(pluginmanager) | ||||||
|         # XXX slightly crude way to initialize capturing |         # XXX slightly crude way to initialize capturing | ||||||
|         import _pytest.capture |         import _pytest.capture | ||||||
|         _pytest.capture.pytest_cmdline_parse(config.pluginmanager, args) |         _pytest.capture.pytest_cmdline_parse(config.pluginmanager, args) | ||||||
|  |  | ||||||
|  | @ -460,8 +460,15 @@ class HookCaller: | ||||||
| _preinit = [] | _preinit = [] | ||||||
| 
 | 
 | ||||||
| def _preloadplugins(): | def _preloadplugins(): | ||||||
|  |     assert not _preinit | ||||||
|     _preinit.append(PluginManager(load=True)) |     _preinit.append(PluginManager(load=True)) | ||||||
| 
 | 
 | ||||||
|  | def get_plugin_manager(): | ||||||
|  |     if _preinit: | ||||||
|  |         return _preinit.pop(0) | ||||||
|  |     else: # subsequent calls to main will create a fresh instance | ||||||
|  |         return PluginManager(load=True) | ||||||
|  | 
 | ||||||
| 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:] | ||||||
|  | @ -471,16 +478,12 @@ def _prepareconfig(args=None, plugins=None): | ||||||
|         if not isinstance(args, str): |         if not isinstance(args, str): | ||||||
|             raise ValueError("not a string or argument list: %r" % (args,)) |             raise ValueError("not a string or argument list: %r" % (args,)) | ||||||
|         args = py.std.shlex.split(args) |         args = py.std.shlex.split(args) | ||||||
|     if _preinit: |     pluginmanager = get_plugin_manager() | ||||||
|        _pluginmanager = _preinit.pop(0) |  | ||||||
|     else: # subsequent calls to main will create a fresh instance |  | ||||||
|         _pluginmanager = PluginManager(load=True) |  | ||||||
|     hook = _pluginmanager.hook |  | ||||||
|     if plugins: |     if plugins: | ||||||
|         for plugin in plugins: |         for plugin in plugins: | ||||||
|             _pluginmanager.register(plugin) |             pluginmanager.register(plugin) | ||||||
|     return hook.pytest_cmdline_parse( |     return pluginmanager.hook.pytest_cmdline_parse( | ||||||
|             pluginmanager=_pluginmanager, args=args) |             pluginmanager=pluginmanager, args=args) | ||||||
| 
 | 
 | ||||||
| def main(args=None, plugins=None): | def main(args=None, plugins=None): | ||||||
|     """ return exit code, after performing an in-process test run. |     """ return exit code, after performing an in-process test run. | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue