From 74523a9d0974018697d8f919244142b35f468253 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 29 Jul 2010 11:22:16 +0200 Subject: [PATCH] avoid loading conftest files which are exactly the same content as a previously loaded conftest file --HG-- branch : trunk --- CHANGELOG | 5 ++++- py/_test/conftesthandle.py | 17 ++++++++++++----- testing/plugin/test_pytest_terminal.py | 2 +- testing/test_conftesthandle.py | 15 +++++++++++++++ tox.ini | 24 +++++++++++------------- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 57a65e31f..9662f12ee 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,11 +1,14 @@ Changes between 1.3.2 and 1.3.3a1 ================================================== +- make conftest loading detect that a conftest file with the same + content was already loaded, avoids surprises in nested directory structures + that can be produced e.g. by Hudson. It alleviates the need to use + --confcutdir at all. - fix terminal coloring for win32 (thanks Michael Foord for reporting) - fix weirdness: make terminal width detection work on stdout instead of stdin (thanks Armin Ronacher for reporting) - - remove trailing whitespace in all py/text files Changes between 1.3.1 and 1.3.2 diff --git a/py/_test/conftesthandle.py b/py/_test/conftesthandle.py index 5637565ea..058bc9dfc 100644 --- a/py/_test/conftesthandle.py +++ b/py/_test/conftesthandle.py @@ -13,6 +13,7 @@ class Conftest(object): self._onimport = onimport self._conftestpath2mod = {} self._confcutdir = confcutdir + self._md5cache = {} def setinitial(self, args): """ try to find a first anchor path for looking up global values @@ -57,17 +58,23 @@ class Conftest(object): if path is None: raise ValueError("missing default confest.") dp = path.dirpath() - if dp == path: - clist = [] - else: + clist = [] + if dp != path: cutdir = self._confcutdir - clist = self.getconftestmodules(dp) if cutdir and path != cutdir and not path.relto(cutdir): pass else: conftestpath = path.join("conftest.py") if conftestpath.check(file=1): - clist.append(self.importconftest(conftestpath)) + key = conftestpath.computehash() + # XXX logging about conftest loading + if key not in self._md5cache: + clist.append(self.importconftest(conftestpath)) + self._md5cache[key] = conftestpath + else: + # use some kind of logging + print ("WARN: not loading %s" % conftestpath) + clist[:0] = self.getconftestmodules(dp) self._path2confmods[path] = clist # be defensive: avoid changes from caller side to # affect us by always returning a copy of the actual list diff --git a/testing/plugin/test_pytest_terminal.py b/testing/plugin/test_pytest_terminal.py index 4eaec2a50..28a522a32 100644 --- a/testing/plugin/test_pytest_terminal.py +++ b/testing/plugin/test_pytest_terminal.py @@ -644,7 +644,7 @@ def pytest_report_header(config): return ["line1", "line2"]""") result = testdir.runpytest("a") result.stdout.fnmatch_lines([ - "*hello: info*", "line1", "line2", + "*hello: info*", ]) diff --git a/testing/test_conftesthandle.py b/testing/test_conftesthandle.py index a0fb6a42c..afa59d572 100644 --- a/testing/test_conftesthandle.py +++ b/testing/test_conftesthandle.py @@ -149,6 +149,21 @@ def test_setinitial_confcut(testdir): assert conftest.getconftestmodules(sub) == [] assert conftest.getconftestmodules(conf.dirpath()) == [] +def test_conftest_samecontent_detection(testdir): + conf = testdir.makeconftest("x=3") + p = testdir.mkdir("x") + conf.copy(p.join("conftest.py")) + conftest = Conftest() + conftest.setinitial([p]) + l = conftest.getconftestmodules(p) + assert len(l) == 1 + assert l[0].__file__ == p.join("conftest.py") + p2 = p.mkdir("y") + conf.copy(p2.join("conftest.py")) + l = conftest.getconftestmodules(p2) + assert len(l) == 1 + assert l[0].__file__ == p.join("conftest.py") + @py.test.mark.multi(name='test tests whatever .dotdir'.split()) def test_setinitial_conftest_subdirs(testdir, name): sub = testdir.mkdir(name) diff --git a/tox.ini b/tox.ini index be8d549aa..30bb40954 100644 --- a/tox.ini +++ b/tox.ini @@ -7,10 +7,9 @@ distshare={toxworkdir}/distshare sdistsrc={distshare}/py-* [testenv] -changedir=testing +changedir=testing commands= - py.test --confcutdir=.. -rfsxX \ - --junitxml={envlogdir}/junit-{envname}.xml --tools-on-path [] + py.test -rfsxX --junitxml={envlogdir}/junit-{envname}.xml --tools-on-path [] deps= pexpect [testenv:py27] @@ -21,7 +20,7 @@ deps= {distshare}/py-* {distshare}/pytest-xdist-* commands= - py.test -n3 --confcutdir=.. -rfsxX \ + py.test -n3 -rfsxX \ --junitxml={envlogdir}/junit-{envname}.xml --tools-on-path [] [testenv:py26] @@ -29,19 +28,18 @@ basepython=python2.6 [testenv:doc] basepython=python changedir={toxinidir} -deps=docutils +deps=docutils pygments {distshare}/py-* {distshare}/pytest-xdist-* - pytest-figleaf + pytest-figleaf pytest-coverage pytest-cov - pytest-capturelog + pytest-capturelog -commands= - {envpython} bin-for-dist/makepluginlist.py - py.test [doc] -rsfxX --confcutdir=. \ - --junitxml={envlogdir}/junit-{envname}s.xml --forcegen +commands= + {envpython} bin-for-dist/makepluginlist.py + py.test [doc] -rsfxX --junitxml={envlogdir}/junit-{envname}s.xml --forcegen [testenv:py25] basepython=python2.5 [testenv:py24] @@ -55,7 +53,7 @@ deps= changedir=testing basepython=jython commands= - {envpython} {envbindir}/py.test-jython --confcutdir=.. \ + {envpython} {envbindir}/py.test-jython \ -rfsxX --junitxml={envlogdir}/junit-{envname}1.xml [io_ code] - {envpython} {envbindir}/py.test-jython --confcutdir=.. \ + {envpython} {envbindir}/py.test-jython \ -rfsxX --junitxml={envlogdir}/junit-{envname}2.xml acceptance_test.py plugin