fix issue151 - heuristcally lookup conftest files on all command line arguments, not just the first existing dir/file

you can install the corresponding pytest-2.3.dev2 via
pip install -i http:/pypi.testrun.org -U pytest
This commit is contained in:
holger krekel 2012-06-26 21:56:03 +02:00
parent 0ba0f91720
commit ecec653e98
4 changed files with 29 additions and 13 deletions

View File

@ -1,2 +1,2 @@
# #
__version__ = '2.3.0.dev1' __version__ = '2.3.0.dev2'

View File

@ -151,20 +151,24 @@ class Conftest(object):
p = current.join(opt1[len(opt)+1:], abs=1) p = current.join(opt1[len(opt)+1:], abs=1)
self._confcutdir = p self._confcutdir = p
break break
for arg in args + [current]: foundanchor = False
for arg in args:
if hasattr(arg, 'startswith') and arg.startswith("--"): if hasattr(arg, 'startswith') and arg.startswith("--"):
continue continue
anchor = current.join(arg, abs=1) anchor = current.join(arg, abs=1)
if anchor.check(): # we found some file object if anchor.check(): # we found some file object
self._path2confmods[None] = self.getconftestmodules(anchor) self._try_load_conftest(anchor)
# let's also consider test* dirs foundanchor = True
if anchor.check(dir=1): if not foundanchor:
for x in anchor.listdir("test*"): self._try_load_conftest(current)
if x.check(dir=1):
self.getconftestmodules(x) def _try_load_conftest(self, anchor):
break self._path2confmods[None] = self.getconftestmodules(anchor)
else: # let's also consider test* subdirs
assert 0, "no root of filesystem?" if anchor.check(dir=1):
for x in anchor.listdir("test*"):
if x.check(dir=1):
self.getconftestmodules(x)
def getconftestmodules(self, path): def getconftestmodules(self, path):
""" return a list of imported conftest modules for the given path. """ """ return a list of imported conftest modules for the given path. """

View File

@ -24,7 +24,7 @@ def main():
name='pytest', name='pytest',
description='py.test: simple powerful testing with Python', description='py.test: simple powerful testing with Python',
long_description = long_description, long_description = long_description,
version='2.3.0.dev1', version='2.3.0.dev2',
url='http://pytest.org', url='http://pytest.org',
license='MIT license', license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

View File

@ -15,7 +15,8 @@ def pytest_funcarg__basedir(request):
d.ensure("adir/__init__.py") d.ensure("adir/__init__.py")
d.ensure("adir/b/__init__.py") d.ensure("adir/b/__init__.py")
return d return d
return request.cached_setup(lambda: basedirmaker(request), extrakey=request.param) return request.cached_setup(
lambda: basedirmaker(request), extrakey=request.param)
def ConftestWithSetinitial(path): def ConftestWithSetinitial(path):
conftest = Conftest() conftest = Conftest()
@ -106,6 +107,17 @@ def test_doubledash_not_considered(testdir):
l = conftest.getconftestmodules(None) l = conftest.getconftestmodules(None)
assert len(l) == 0 assert len(l) == 0
def test_issue151_load_all_conftests(testdir):
names = "code proj src".split()
for name in names:
p = testdir.mkdir(name)
p.ensure("conftest.py")
conftest = Conftest()
conftest.setinitial(names)
d = list(conftest._conftestpath2mod.values())
assert len(d) == len(names)
def test_conftest_global_import(testdir): def test_conftest_global_import(testdir):
testdir.makeconftest("x=3") testdir.makeconftest("x=3")
p = testdir.makepyfile(""" p = testdir.makepyfile("""