avoid loading conftest files which are exactly the same content as a previously loaded conftest file

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-07-29 11:22:16 +02:00
parent e5d09b771a
commit 74523a9d09
5 changed files with 43 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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

24
tox.ini
View File

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