actually look into all non-dot subdirs for conftest.py files - recursive walk would be too heavy for large source trees but first-level subdirs are fine IMO. Note that prior to py.test 1.0 doing this "look-ahead" was not easily doable because it was hard to avoid global state in conftest.py, this is not true anymore - so i feel ok telling people to cleanup their conftest files if they get problems (you can imagine people doing all kinds of things at global conftest.py module scope, can't you?)
--HG-- branch : trunk
This commit is contained in:
parent
105ed6dcaa
commit
d163d92b33
|
@ -15,9 +15,9 @@ Changes between 1.2.1 and 1.2.0
|
|||
|
||||
- display a short and concise traceback if a funcarg lookup fails
|
||||
|
||||
- early-load "test*/conftest.py" files, i.e. conftest.py files in
|
||||
directories starting with 'test'. allows to conveniently keep and access
|
||||
test-related options without having to put a conftest.py into the package root dir.
|
||||
- early-load "conftest.py" files in non-dot first-level sub directories.
|
||||
allows to conveniently keep and access test-related options without
|
||||
having to put a conftest.py into the package root dir.
|
||||
|
||||
- fix issue67: new super-short traceback-printing option: "--tb=line" will print a single line for each failing (python) test indicating its filename, lineno and the failure value
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class Conftest(object):
|
|||
self._path2confmods[None] = self.getconftestmodules(anchor)
|
||||
# let's also consider test* dirs
|
||||
if anchor.check(dir=1):
|
||||
for x in anchor.listdir("test*"):
|
||||
for x in anchor.listdir(lambda x: x.check(dir=1, dotfile=0)):
|
||||
self.getconftestmodules(x)
|
||||
break
|
||||
else:
|
||||
|
|
|
@ -32,7 +32,7 @@ class TestConftestValueAccessGlobal:
|
|||
l = []
|
||||
conftest = Conftest(onimport=l.append)
|
||||
conftest.setinitial([basedir.join("adir")])
|
||||
assert len(l) == 1
|
||||
assert len(l) == 2
|
||||
assert conftest.rget("a") == 1
|
||||
assert conftest.rget("b", basedir.join("adir", "b")) == 2
|
||||
assert len(l) == 2
|
||||
|
@ -133,18 +133,15 @@ def test_setinitial_confcut(testdir):
|
|||
assert conftest.getconftestmodules(sub) == []
|
||||
assert conftest.getconftestmodules(conf.dirpath()) == []
|
||||
|
||||
def test_setinitial_not_considers_conftest_in_non_test_dirs(testdir):
|
||||
sub = testdir.mkdir("sub")
|
||||
sub.ensure("conftest.py")
|
||||
conftest = Conftest()
|
||||
conftest.setinitial([sub.dirpath()])
|
||||
assert not conftest._conftestpath2mod
|
||||
|
||||
@py.test.mark.multi(name='test tests testing'.split())
|
||||
def test_setinitial_considers_conftest_in_test_dirs(testdir, name):
|
||||
@py.test.mark.multi(name='test tests whatever .dotdir'.split())
|
||||
def test_setinitial_conftest_subdirs(testdir, name):
|
||||
sub = testdir.mkdir(name)
|
||||
subconftest = sub.ensure("conftest.py")
|
||||
conftest = Conftest()
|
||||
conftest.setinitial([sub.dirpath()])
|
||||
assert subconftest in conftest._conftestpath2mod
|
||||
assert len(conftest._conftestpath2mod) == 1
|
||||
if name != ".dotdir":
|
||||
assert subconftest in conftest._conftestpath2mod
|
||||
assert len(conftest._conftestpath2mod) == 1
|
||||
else:
|
||||
assert subconftest not in conftest._conftestpath2mod
|
||||
assert len(conftest._conftestpath2mod) == 0
|
||||
|
|
|
@ -24,15 +24,6 @@ class Test_genitems:
|
|||
p = testdir.makepyfile(conftest="raise SyntaxError\n")
|
||||
py.test.raises(SyntaxError, testdir.inline_genitems, p.dirpath())
|
||||
|
||||
def test_subdir_conftest_error(self, testdir):
|
||||
tmp = testdir.tmpdir
|
||||
tmp.ensure("sub", "conftest.py").write("raise SyntaxError('x')\n")
|
||||
items, reprec = testdir.inline_genitems(tmp)
|
||||
collectionfailures = reprec.getfailedcollections()
|
||||
assert len(collectionfailures) == 1
|
||||
ev = collectionfailures[0]
|
||||
assert "SyntaxError: x" in ev.longrepr.reprcrash.message
|
||||
|
||||
def test_example_items1(self, testdir):
|
||||
p = testdir.makepyfile('''
|
||||
def testone():
|
||||
|
|
Loading…
Reference in New Issue