From 7bd60b5abb66e10cb107f79e412bfbb576e84b8b Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 4 Feb 2010 12:26:53 +0100 Subject: [PATCH] check and load test*/conftest.py early from anchors - this makes it a bit more convenient to have command line options available from a root directory of a project that does not directly contain a conftest.py --HG-- branch : trunk --- CHANGELOG | 3 +++ py/_test/conftesthandle.py | 4 ++++ testing/test_conftesthandle.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index dd393842a..0b5ee2fef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ Changes between 1.2.1 and 1.2.0 ===================================== +- 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. - 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 - fix issue78: always call python-level teardown functions even if the according setup failed. This includes refinements for calling setup_module/class functions diff --git a/py/_test/conftesthandle.py b/py/_test/conftesthandle.py index fcfae18bf..598a5fbaf 100644 --- a/py/_test/conftesthandle.py +++ b/py/_test/conftesthandle.py @@ -39,6 +39,10 @@ class Conftest(object): 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*"): + self.getconftestmodules(x) break else: assert 0, "no root of filesystem?" diff --git a/testing/test_conftesthandle.py b/testing/test_conftesthandle.py index c1fc7e2ab..9780c26c9 100644 --- a/testing/test_conftesthandle.py +++ b/testing/test_conftesthandle.py @@ -132,3 +132,19 @@ def test_setinitial_confcut(testdir): assert conftest._confcutdir == sub 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): + 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