diff --git a/py/test/config.py b/py/test/config.py index 5664e318f..d3427e715 100644 --- a/py/test/config.py +++ b/py/test/config.py @@ -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. """ diff --git a/py/test/conftesthandle.py b/py/test/conftesthandle.py index 0548f53e6..dd87962d7 100644 --- a/py/test/conftesthandle.py +++ b/py/test/conftesthandle.py @@ -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, diff --git a/py/test/testing/test_conftesthandle.py b/py/test/testing/test_conftesthandle.py index a95cb0591..5a2dd6385 100644 --- a/py/test/testing/test_conftesthandle.py +++ b/py/test/testing/test_conftesthandle.py @@ -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)