avoid direct circular reference between config and pluginmanager

--HG--
branch : more_plugin
This commit is contained in:
holger krekel 2015-04-25 18:14:41 +02:00
parent 7364647f2f
commit 9c5495832c
3 changed files with 15 additions and 16 deletions

View File

@ -60,17 +60,17 @@ builtin_plugins.add("pytester")
def _preloadplugins():
assert not _preinit
_preinit.append(get_plugin_manager())
_preinit.append(get_config())
def get_plugin_manager():
def get_config():
if _preinit:
return _preinit.pop(0)
# subsequent calls to main will create a fresh instance
pluginmanager = PytestPluginManager()
pluginmanager.config = Config(pluginmanager) # XXX attr needed?
config = Config(pluginmanager)
for spec in default_plugins:
pluginmanager.import_plugin(spec)
return pluginmanager
return config
def _prepareconfig(args=None, plugins=None):
if args is None:
@ -81,7 +81,7 @@ def _prepareconfig(args=None, plugins=None):
if not isinstance(args, str):
raise ValueError("not a string or argument list: %r" % (args,))
args = shlex.split(args)
pluginmanager = get_plugin_manager()
pluginmanager = get_config().pluginmanager
if plugins:
for plugin in plugins:
pluginmanager.register(plugin)
@ -738,7 +738,7 @@ class Config(object):
return self.pluginmanager.getplugin("terminalreporter")._tw
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)
return self
@ -768,8 +768,7 @@ class Config(object):
@classmethod
def fromdictargs(cls, option_dict, args):
""" constructor useable for subprocesses. """
pluginmanager = get_plugin_manager()
config = pluginmanager.config
config = get_config()
config._preparse(args, addopts=False)
config.option.__dict__.update(option_dict)
for x in config.option.plugins:

View File

@ -348,8 +348,8 @@ def test_notify_exception(testdir, capfd):
def test_load_initial_conftest_last_ordering(testdir):
from _pytest.config import get_plugin_manager
pm = get_plugin_manager()
from _pytest.config import get_config
pm = get_config().pluginmanager
class My:
def pytest_load_initial_conftests(self):
pass

View File

@ -1,6 +1,6 @@
import pytest, py, os
from _pytest.core import * # noqa
from _pytest.config import get_plugin_manager
from _pytest.config import get_config
@pytest.fixture
@ -41,14 +41,14 @@ class TestPluginManager:
pytestpm.check_pending()
def test_register_mismatch_arg(self):
pm = get_plugin_manager()
pm = get_config().pluginmanager
class hello:
def pytest_configure(self, asd):
pass
pytest.raises(Exception, lambda: pm.register(hello()))
def test_register(self):
pm = get_plugin_manager()
pm = get_config().pluginmanager
class MyPlugin:
pass
my = MyPlugin()
@ -340,7 +340,7 @@ class TestPytestPluginInteractions:
def pytest_myhook(xyz):
return xyz + 1
""")
config = get_plugin_manager().config
config = get_config()
pm = config.pluginmanager
pm.hook.pytest_addhooks.call_historic(
kwargs=dict(pluginmanager=config.pluginmanager))
@ -416,7 +416,7 @@ class TestPytestPluginInteractions:
assert len(l) == 2
def test_hook_tracing(self):
pytestpm = get_plugin_manager() # fully initialized with plugins
pytestpm = get_config().pluginmanager # fully initialized with plugins
saveindent = []
class api1:
def pytest_plugin_registered(self):
@ -927,7 +927,7 @@ class TestPytestPluginManager:
assert pytestpm.getplugin("pytest_p2").__name__ == "pytest_p2"
def test_consider_module_import_module(self, testdir):
pytestpm = get_plugin_manager()
pytestpm = get_config().pluginmanager
mod = py.std.types.ModuleType("x")
mod.pytest_plugins = "pytest_a"
aplugin = testdir.makepyfile(pytest_a="#")