simplify Config constructor

This commit is contained in:
holger krekel 2013-09-28 22:22:53 +02:00
parent b80e875525
commit fad7bd4393
4 changed files with 6 additions and 6 deletions

View File

@ -495,7 +495,7 @@ FILE_OR_DIR = 'file_or_dir'
class Config(object): class Config(object):
""" access to configuration values, pluginmanager and plugin hooks. """ """ access to configuration values, pluginmanager and plugin hooks. """
def __init__(self, pluginmanager=None): def __init__(self, pluginmanager):
#: access to command line option as attributes. #: access to command line option as attributes.
#: (deprecated), use :py:func:`getoption() <_pytest.config.Config.getoption>` instead #: (deprecated), use :py:func:`getoption() <_pytest.config.Config.getoption>` instead
self.option = CmdOptions() self.option = CmdOptions()
@ -505,7 +505,7 @@ class Config(object):
processopt=self._processopt, processopt=self._processopt,
) )
#: a pluginmanager instance #: a pluginmanager instance
self.pluginmanager = pluginmanager or PluginManager(load=True) self.pluginmanager = pluginmanager
self.trace = self.pluginmanager.trace.root.get("config") self.trace = self.pluginmanager.trace.root.get("config")
self._conftest = Conftest(onimport=self._onimportconftest) self._conftest = Conftest(onimport=self._onimportconftest)
self.hook = self.pluginmanager.hook self.hook = self.pluginmanager.hook
@ -516,7 +516,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. """
config = cls() config = cls(PluginManager(load=True))
# 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)

View File

@ -82,7 +82,7 @@ class TestConfigCmdlineParsing:
class TestConfigAPI: class TestConfigAPI:
def test_config_trace(self, testdir): def test_config_trace(self, testdir):
config = testdir.Config() config = testdir.parseconfig()
l = [] l = []
config.trace.root.setwriter(l.append) config.trace.root.setwriter(l.append)
config.trace("hello") config.trace("hello")

View File

@ -319,7 +319,7 @@ class TestPytestPluginInteractions:
def pytest_myhook(xyz): def pytest_myhook(xyz):
return xyz + 1 return xyz + 1
""") """)
config = testdir.Config() config = testdir.Config(PluginManager(load=True))
config._conftest.importconftest(conf) config._conftest.importconftest(conf)
print(config.pluginmanager.getplugins()) print(config.pluginmanager.getplugins())
res = config.hook.pytest_myhook(xyz=10) res = config.hook.pytest_myhook(xyz=10)

View File

@ -36,7 +36,7 @@ def test_ensuretemp(recwarn):
class TestTempdirHandler: class TestTempdirHandler:
def test_mktemp(self, testdir): def test_mktemp(self, testdir):
config = testdir.Config() config = testdir.parseconfig()
config.option.basetemp = testdir.mkdir("hello") config.option.basetemp = testdir.mkdir("hello")
t = TempdirHandler(config) t = TempdirHandler(config)
tmp = t.mktemp("world") tmp = t.mktemp("world")