[py-svn] py-trunk commit 3e28f12e7c44: avoid loading conftest files which are exactly the same content as a previously loaded conftest file

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Jul 29 11:23:04 CEST 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User holger krekel <holger at merlinux.eu>
# Date 1280395336 -7200
# Node ID 3e28f12e7c443367ed0ed63f605aae68b96b512b
# Parent  2822b3c23af39c523050a1b6ff5fed27cdcd58ff
avoid loading conftest files which are exactly the same content as a previously loaded conftest file

--- 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*",
         ])

--- 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

--- 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

--- 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)

--- 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



More information about the pytest-commit mailing list