[svn r37433] Add a helper which returns value + path of a dir where value was found

--HG--
branch : trunk
This commit is contained in:
fijal 2007-01-27 15:01:45 +01:00
parent 50a0a04bd2
commit f1b4e14f09
3 changed files with 23 additions and 5 deletions

View File

@ -117,7 +117,14 @@ class Config(object):
try:
return self._overwrite_dict[name]
except KeyError:
return self.conftest.rget(name, path)
return self.conftest.rget(name, path)
def getvalue_and_confpath(self, name, path=None):
""" same as previous, but returns conftest's path
as well
"""
val, mod = self.conftest.rget_path(name, path)
return val, py.path.local(mod.__file__).dirpath()
def initsession(self):
""" return an initialized session object. """

View File

@ -57,19 +57,24 @@ class Conftest(object):
# return self._get(name, modules)
def rget(self, name, path=None):
return self._rget(name, path)[0]
def _rget(self, name, path=None):
modules = self.getconftestmodules(path)
modules.reverse()
return self._get(name, modules)
return self._get(name, modules)
def rget_path(self, name, path=None):
return self._rget(name, path)
def _get(self, name, modules):
for mod in modules:
for mod in modules:
try:
return getattr(mod, name)
return getattr(mod, name), mod
except AttributeError:
continue
raise KeyError, name
def importconfig(configpath):
if not configpath.dirpath('__init__.py').check(file=1):
# HACK: we don't want any "globally" imported conftest.py,

View File

@ -65,6 +65,12 @@ class TestConftestValueAccessGlobal:
#conftest.lget("a") == 1
#conftest.lget("b") == 1
def test_value_access_path(self):
topdir = self.basedir.join("adir", "b")
conftest = Conftest(topdir)
_, mod = conftest.rget_path("a")
assert py.path.local(mod.__file__).dirpath() == topdir
class TestConftestValueAccessInPackage(TestConftestValueAccessGlobal):
def setup_class(cls):
TestConftestValueAccessGlobal.__dict__['setup_class'](cls)