From d163d92b33b660a022035be8ebd688aa86456a7a Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sat, 6 Feb 2010 22:37:04 +0100 Subject: [PATCH] actually look into all non-dot subdirs for conftest.py files - recursive walk would be too heavy for large source trees but first-level subdirs are fine IMO. Note that prior to py.test 1.0 doing this "look-ahead" was not easily doable because it was hard to avoid global state in conftest.py, this is not true anymore - so i feel ok telling people to cleanup their conftest files if they get problems (you can imagine people doing all kinds of things at global conftest.py module scope, can't you?) --HG-- branch : trunk --- CHANGELOG | 6 +++--- py/_test/conftesthandle.py | 2 +- testing/test_conftesthandle.py | 21 +++++++++------------ testing/test_genitems.py | 9 --------- 4 files changed, 13 insertions(+), 25 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 7162c68f3..19442995a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,9 +15,9 @@ Changes between 1.2.1 and 1.2.0 - display a short and concise traceback if a funcarg lookup fails -- early-load "test*/conftest.py" files, i.e. conftest.py files in - directories starting with 'test'. allows to conveniently keep and access - test-related options without having to put a conftest.py into the package root dir. +- early-load "conftest.py" files in non-dot first-level sub directories. + allows to conveniently keep and access test-related options without + having to put a conftest.py into the package root dir. - fix issue67: new super-short traceback-printing option: "--tb=line" will print a single line for each failing (python) test indicating its filename, lineno and the failure value diff --git a/py/_test/conftesthandle.py b/py/_test/conftesthandle.py index 598a5fbaf..8c345eb37 100644 --- a/py/_test/conftesthandle.py +++ b/py/_test/conftesthandle.py @@ -41,7 +41,7 @@ class Conftest(object): self._path2confmods[None] = self.getconftestmodules(anchor) # let's also consider test* dirs if anchor.check(dir=1): - for x in anchor.listdir("test*"): + for x in anchor.listdir(lambda x: x.check(dir=1, dotfile=0)): self.getconftestmodules(x) break else: diff --git a/testing/test_conftesthandle.py b/testing/test_conftesthandle.py index 9780c26c9..3861130f1 100644 --- a/testing/test_conftesthandle.py +++ b/testing/test_conftesthandle.py @@ -32,7 +32,7 @@ class TestConftestValueAccessGlobal: l = [] conftest = Conftest(onimport=l.append) conftest.setinitial([basedir.join("adir")]) - assert len(l) == 1 + assert len(l) == 2 assert conftest.rget("a") == 1 assert conftest.rget("b", basedir.join("adir", "b")) == 2 assert len(l) == 2 @@ -133,18 +133,15 @@ def test_setinitial_confcut(testdir): assert conftest.getconftestmodules(sub) == [] assert conftest.getconftestmodules(conf.dirpath()) == [] -def test_setinitial_not_considers_conftest_in_non_test_dirs(testdir): - sub = testdir.mkdir("sub") - sub.ensure("conftest.py") - conftest = Conftest() - conftest.setinitial([sub.dirpath()]) - assert not conftest._conftestpath2mod - -@py.test.mark.multi(name='test tests testing'.split()) -def test_setinitial_considers_conftest_in_test_dirs(testdir, name): +@py.test.mark.multi(name='test tests whatever .dotdir'.split()) +def test_setinitial_conftest_subdirs(testdir, name): sub = testdir.mkdir(name) subconftest = sub.ensure("conftest.py") conftest = Conftest() conftest.setinitial([sub.dirpath()]) - assert subconftest in conftest._conftestpath2mod - assert len(conftest._conftestpath2mod) == 1 + if name != ".dotdir": + assert subconftest in conftest._conftestpath2mod + assert len(conftest._conftestpath2mod) == 1 + else: + assert subconftest not in conftest._conftestpath2mod + assert len(conftest._conftestpath2mod) == 0 diff --git a/testing/test_genitems.py b/testing/test_genitems.py index 2857f1685..876f4ee5b 100644 --- a/testing/test_genitems.py +++ b/testing/test_genitems.py @@ -24,15 +24,6 @@ class Test_genitems: p = testdir.makepyfile(conftest="raise SyntaxError\n") py.test.raises(SyntaxError, testdir.inline_genitems, p.dirpath()) - def test_subdir_conftest_error(self, testdir): - tmp = testdir.tmpdir - tmp.ensure("sub", "conftest.py").write("raise SyntaxError('x')\n") - items, reprec = testdir.inline_genitems(tmp) - collectionfailures = reprec.getfailedcollections() - assert len(collectionfailures) == 1 - ev = collectionfailures[0] - assert "SyntaxError: x" in ev.longrepr.reprcrash.message - def test_example_items1(self, testdir): p = testdir.makepyfile(''' def testone():