From ecec653e98158a6eb32b9c303527d5de169850eb Mon Sep 17 00:00:00 2001 From: holger krekel Date: Tue, 26 Jun 2012 21:56:03 +0200 Subject: [PATCH] fix issue151 - heuristcally lookup conftest files on all command line arguments, not just the first existing dir/file you can install the corresponding pytest-2.3.dev2 via pip install -i http:/pypi.testrun.org -U pytest --- _pytest/__init__.py | 2 +- _pytest/config.py | 24 ++++++++++++++---------- setup.py | 2 +- testing/test_conftest.py | 14 +++++++++++++- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/_pytest/__init__.py b/_pytest/__init__.py index 9405eb038..39b831d87 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.3.0.dev1' +__version__ = '2.3.0.dev2' diff --git a/_pytest/config.py b/_pytest/config.py index e1b240d3c..7e0f9ead6 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -151,20 +151,24 @@ class Conftest(object): p = current.join(opt1[len(opt)+1:], abs=1) self._confcutdir = p break - for arg in args + [current]: + foundanchor = False + for arg in args: if hasattr(arg, 'startswith') and arg.startswith("--"): continue anchor = current.join(arg, abs=1) if anchor.check(): # we found some file object - self._path2confmods[None] = self.getconftestmodules(anchor) - # let's also consider test* dirs - if anchor.check(dir=1): - for x in anchor.listdir("test*"): - if x.check(dir=1): - self.getconftestmodules(x) - break - else: - assert 0, "no root of filesystem?" + self._try_load_conftest(anchor) + foundanchor = True + if not foundanchor: + self._try_load_conftest(current) + + def _try_load_conftest(self, anchor): + self._path2confmods[None] = self.getconftestmodules(anchor) + # let's also consider test* subdirs + if anchor.check(dir=1): + for x in anchor.listdir("test*"): + if x.check(dir=1): + self.getconftestmodules(x) def getconftestmodules(self, path): """ return a list of imported conftest modules for the given path. """ diff --git a/setup.py b/setup.py index fee8f8f55..d25b3f533 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def main(): name='pytest', description='py.test: simple powerful testing with Python', long_description = long_description, - version='2.3.0.dev1', + version='2.3.0.dev2', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], diff --git a/testing/test_conftest.py b/testing/test_conftest.py index 1a2bdfe77..d4ec62bb8 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -15,7 +15,8 @@ def pytest_funcarg__basedir(request): d.ensure("adir/__init__.py") d.ensure("adir/b/__init__.py") return d - return request.cached_setup(lambda: basedirmaker(request), extrakey=request.param) + return request.cached_setup( + lambda: basedirmaker(request), extrakey=request.param) def ConftestWithSetinitial(path): conftest = Conftest() @@ -106,6 +107,17 @@ def test_doubledash_not_considered(testdir): l = conftest.getconftestmodules(None) assert len(l) == 0 +def test_issue151_load_all_conftests(testdir): + names = "code proj src".split() + for name in names: + p = testdir.mkdir(name) + p.ensure("conftest.py") + + conftest = Conftest() + conftest.setinitial(names) + d = list(conftest._conftestpath2mod.values()) + assert len(d) == len(names) + def test_conftest_global_import(testdir): testdir.makeconftest("x=3") p = testdir.makepyfile("""