simplify Config initialization

--HG--
branch : trunk
This commit is contained in:
holger krekel 2009-12-29 14:13:12 +01:00
parent 71e332c9c4
commit 080fd2880e
2 changed files with 13 additions and 26 deletions

View File

@ -20,27 +20,22 @@ class Error(Exception):
""" Test Configuration Error. """ """ Test Configuration Error. """
class Config(object): class Config(object):
""" test configuration object, provides access to config valueso, """ access to config values, pluginmanager and plugin hooks. """
the pluginmanager and plugin api.
"""
Option = py.std.optparse.Option Option = py.std.optparse.Option
Error = Error Error = Error
basetemp = None basetemp = None
_sessionclass = None _sessionclass = None
def __init__(self, pluginmanager=None, topdir=None): def __init__(self, topdir=None):
self.option = CmdOptions() self.option = CmdOptions()
self.topdir = topdir self.topdir = topdir
self._parser = parseopt.Parser( self._parser = parseopt.Parser(
usage="usage: %prog [options] [file_or_dir] [file_or_dir] [...]", usage="usage: %prog [options] [file_or_dir] [file_or_dir] [...]",
processopt=self._processopt, processopt=self._processopt,
) )
if pluginmanager is None: self.pluginmanager = py.test._PluginManager()
pluginmanager = py.test._PluginManager()
assert isinstance(pluginmanager, py.test._PluginManager)
self.pluginmanager = pluginmanager
self._conftest = Conftest(onimport=self._onimportconftest) self._conftest = Conftest(onimport=self._onimportconftest)
self.hook = pluginmanager.hook self.hook = self.pluginmanager.hook
def _onimportconftest(self, conftestmodule): def _onimportconftest(self, conftestmodule):
self.trace("loaded conftestmodule %r" %(conftestmodule,)) self.trace("loaded conftestmodule %r" %(conftestmodule,))
@ -104,17 +99,12 @@ class Config(object):
return l, self.option return l, self.option
def __setstate__(self, repr): def __setstate__(self, repr):
# warning global side effects: # we have to set py.test.config because loading
# * registering to py lib plugins # of conftest files may use it (deprecated)
# * setting py.test.config # mainly by py.test.config.addoptions()
self.__init__(
pluginmanager=py.test._PluginManager(),
topdir=py.path.local(),
)
# we have to set py.test.config because preparse()
# might load conftest files which have
# py.test.config.addoptions() lines in them
py.test.config = self py.test.config = self
# next line will registers default plugins
self.__init__(topdir=py.path.local())
args, cmdlineopts = repr args, cmdlineopts = repr
args = [self.topdir.join(x) for x in args] args = [self.topdir.join(x) for x in args]
self.option = cmdlineopts self.option = cmdlineopts
@ -307,8 +297,5 @@ def gettopdir(args):
return pkgdir.dirpath() return pkgdir.dirpath()
# this is the one per-process instance of py.test configuration # this is default per-process instance of py.test configuration
config_per_process = Config( config_per_process = Config()
pluginmanager=py.test._PluginManager()
)

View File

@ -66,10 +66,10 @@ class TmpTestdir:
def __repr__(self): def __repr__(self):
return "<TmpTestdir %r>" % (self.tmpdir,) return "<TmpTestdir %r>" % (self.tmpdir,)
def Config(self, registry=None, topdir=None): def Config(self, topdir=None):
if topdir is None: if topdir is None:
topdir = self.tmpdir.dirpath() topdir = self.tmpdir.dirpath()
return pytestConfig(registry, topdir=topdir) return pytestConfig(topdir=topdir)
def finalize(self): def finalize(self):
for p in self._syspathremove: for p in self._syspathremove: