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:
parent
0ba0f91720
commit
ecec653e98
|
@ -1,2 +1,2 @@
|
|||
#
|
||||
__version__ = '2.3.0.dev1'
|
||||
__version__ = '2.3.0.dev2'
|
||||
|
|
|
@ -151,20 +151,24 @@ class Conftest(object):
|
|||
p = current.join(opt1[len(opt)+1:], abs=1)
|
||||
self._confcutdir = p
|
||||
break
|
||||
for arg in args + [current]:
|
||||
foundanchor = False
|
||||
for arg in args:
|
||||
if hasattr(arg, 'startswith') and arg.startswith("--"):
|
||||
continue
|
||||
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*"):
|
||||
if x.check(dir=1):
|
||||
self.getconftestmodules(x)
|
||||
break
|
||||
else:
|
||||
assert 0, "no root of filesystem?"
|
||||
self._try_load_conftest(anchor)
|
||||
foundanchor = True
|
||||
if not foundanchor:
|
||||
self._try_load_conftest(current)
|
||||
|
||||
def _try_load_conftest(self, anchor):
|
||||
self._path2confmods[None] = self.getconftestmodules(anchor)
|
||||
# let's also consider test* subdirs
|
||||
if anchor.check(dir=1):
|
||||
for x in anchor.listdir("test*"):
|
||||
if x.check(dir=1):
|
||||
self.getconftestmodules(x)
|
||||
|
||||
def getconftestmodules(self, path):
|
||||
""" return a list of imported conftest modules for the given path. """
|
||||
|
|
2
setup.py
2
setup.py
|
@ -24,7 +24,7 @@ def main():
|
|||
name='pytest',
|
||||
description='py.test: simple powerful testing with Python',
|
||||
long_description = long_description,
|
||||
version='2.3.0.dev1',
|
||||
version='2.3.0.dev2',
|
||||
url='http://pytest.org',
|
||||
license='MIT license',
|
||||
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],
|
||||
|
|
|
@ -15,7 +15,8 @@ def pytest_funcarg__basedir(request):
|
|||
d.ensure("adir/__init__.py")
|
||||
d.ensure("adir/b/__init__.py")
|
||||
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):
|
||||
conftest = Conftest()
|
||||
|
@ -106,6 +107,17 @@ def test_doubledash_not_considered(testdir):
|
|||
l = conftest.getconftestmodules(None)
|
||||
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):
|
||||
testdir.makeconftest("x=3")
|
||||
p = testdir.makepyfile("""
|
||||
|
|
Loading…
Reference in New Issue