avoid direct circular reference between config and pluginmanager
--HG-- branch : more_plugin
This commit is contained in:
		
							parent
							
								
									7364647f2f
								
							
						
					
					
						commit
						9c5495832c
					
				|  | @ -60,17 +60,17 @@ builtin_plugins.add("pytester") | ||||||
| 
 | 
 | ||||||
| def _preloadplugins(): | def _preloadplugins(): | ||||||
|     assert not _preinit |     assert not _preinit | ||||||
|     _preinit.append(get_plugin_manager()) |     _preinit.append(get_config()) | ||||||
| 
 | 
 | ||||||
| def get_plugin_manager(): | def get_config(): | ||||||
|     if _preinit: |     if _preinit: | ||||||
|         return _preinit.pop(0) |         return _preinit.pop(0) | ||||||
|     # subsequent calls to main will create a fresh instance |     # subsequent calls to main will create a fresh instance | ||||||
|     pluginmanager = PytestPluginManager() |     pluginmanager = PytestPluginManager() | ||||||
|     pluginmanager.config = Config(pluginmanager) # XXX attr needed? |     config = Config(pluginmanager) | ||||||
|     for spec in default_plugins: |     for spec in default_plugins: | ||||||
|         pluginmanager.import_plugin(spec) |         pluginmanager.import_plugin(spec) | ||||||
|     return pluginmanager |     return config | ||||||
| 
 | 
 | ||||||
| def _prepareconfig(args=None, plugins=None): | def _prepareconfig(args=None, plugins=None): | ||||||
|     if args is None: |     if args is None: | ||||||
|  | @ -81,7 +81,7 @@ 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 = shlex.split(args) |         args = shlex.split(args) | ||||||
|     pluginmanager = get_plugin_manager() |     pluginmanager = get_config().pluginmanager | ||||||
|     if plugins: |     if plugins: | ||||||
|         for plugin in plugins: |         for plugin in plugins: | ||||||
|             pluginmanager.register(plugin) |             pluginmanager.register(plugin) | ||||||
|  | @ -738,7 +738,7 @@ class Config(object): | ||||||
|         return self.pluginmanager.getplugin("terminalreporter")._tw |         return self.pluginmanager.getplugin("terminalreporter")._tw | ||||||
| 
 | 
 | ||||||
|     def pytest_cmdline_parse(self, pluginmanager, args): |     def pytest_cmdline_parse(self, pluginmanager, args): | ||||||
|         assert self == pluginmanager.config, (self, pluginmanager.config) |         # REF1 assert self == pluginmanager.config, (self, pluginmanager.config) | ||||||
|         self.parse(args) |         self.parse(args) | ||||||
|         return self |         return self | ||||||
| 
 | 
 | ||||||
|  | @ -768,8 +768,7 @@ 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. """ | ||||||
|         pluginmanager = get_plugin_manager() |         config = get_config() | ||||||
|         config = pluginmanager.config |  | ||||||
|         config._preparse(args, addopts=False) |         config._preparse(args, addopts=False) | ||||||
|         config.option.__dict__.update(option_dict) |         config.option.__dict__.update(option_dict) | ||||||
|         for x in config.option.plugins: |         for x in config.option.plugins: | ||||||
|  |  | ||||||
|  | @ -348,8 +348,8 @@ def test_notify_exception(testdir, capfd): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_load_initial_conftest_last_ordering(testdir): | def test_load_initial_conftest_last_ordering(testdir): | ||||||
|     from _pytest.config  import get_plugin_manager |     from _pytest.config  import get_config | ||||||
|     pm = get_plugin_manager() |     pm = get_config().pluginmanager | ||||||
|     class My: |     class My: | ||||||
|         def pytest_load_initial_conftests(self): |         def pytest_load_initial_conftests(self): | ||||||
|             pass |             pass | ||||||
|  |  | ||||||
|  | @ -1,6 +1,6 @@ | ||||||
| import pytest, py, os | import pytest, py, os | ||||||
| from _pytest.core import * # noqa | from _pytest.core import * # noqa | ||||||
| from _pytest.config import get_plugin_manager | from _pytest.config import get_config | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @pytest.fixture | @pytest.fixture | ||||||
|  | @ -41,14 +41,14 @@ class TestPluginManager: | ||||||
|             pytestpm.check_pending() |             pytestpm.check_pending() | ||||||
| 
 | 
 | ||||||
|     def test_register_mismatch_arg(self): |     def test_register_mismatch_arg(self): | ||||||
|         pm = get_plugin_manager() |         pm = get_config().pluginmanager | ||||||
|         class hello: |         class hello: | ||||||
|             def pytest_configure(self, asd): |             def pytest_configure(self, asd): | ||||||
|                 pass |                 pass | ||||||
|         pytest.raises(Exception, lambda: pm.register(hello())) |         pytest.raises(Exception, lambda: pm.register(hello())) | ||||||
| 
 | 
 | ||||||
|     def test_register(self): |     def test_register(self): | ||||||
|         pm = get_plugin_manager() |         pm = get_config().pluginmanager | ||||||
|         class MyPlugin: |         class MyPlugin: | ||||||
|             pass |             pass | ||||||
|         my = MyPlugin() |         my = MyPlugin() | ||||||
|  | @ -340,7 +340,7 @@ class TestPytestPluginInteractions: | ||||||
|             def pytest_myhook(xyz): |             def pytest_myhook(xyz): | ||||||
|                 return xyz + 1 |                 return xyz + 1 | ||||||
|         """) |         """) | ||||||
|         config = get_plugin_manager().config |         config = get_config() | ||||||
|         pm = config.pluginmanager |         pm = config.pluginmanager | ||||||
|         pm.hook.pytest_addhooks.call_historic( |         pm.hook.pytest_addhooks.call_historic( | ||||||
|                                 kwargs=dict(pluginmanager=config.pluginmanager)) |                                 kwargs=dict(pluginmanager=config.pluginmanager)) | ||||||
|  | @ -416,7 +416,7 @@ class TestPytestPluginInteractions: | ||||||
|         assert len(l) == 2 |         assert len(l) == 2 | ||||||
| 
 | 
 | ||||||
|     def test_hook_tracing(self): |     def test_hook_tracing(self): | ||||||
|         pytestpm = get_plugin_manager()  # fully initialized with plugins |         pytestpm = get_config().pluginmanager  # fully initialized with plugins | ||||||
|         saveindent = [] |         saveindent = [] | ||||||
|         class api1: |         class api1: | ||||||
|             def pytest_plugin_registered(self): |             def pytest_plugin_registered(self): | ||||||
|  | @ -927,7 +927,7 @@ class TestPytestPluginManager: | ||||||
|         assert pytestpm.getplugin("pytest_p2").__name__ == "pytest_p2" |         assert pytestpm.getplugin("pytest_p2").__name__ == "pytest_p2" | ||||||
| 
 | 
 | ||||||
|     def test_consider_module_import_module(self, testdir): |     def test_consider_module_import_module(self, testdir): | ||||||
|         pytestpm = get_plugin_manager() |         pytestpm = get_config().pluginmanager | ||||||
|         mod = py.std.types.ModuleType("x") |         mod = py.std.types.ModuleType("x") | ||||||
|         mod.pytest_plugins = "pytest_a" |         mod.pytest_plugins = "pytest_a" | ||||||
|         aplugin = testdir.makepyfile(pytest_a="#") |         aplugin = testdir.makepyfile(pytest_a="#") | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue