fix issue 109 - sibling conftest.py files shall not be loaded.

also simplify / refine tests a bit.

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-10-04 16:19:01 +02:00
parent 4eb45dab08
commit 29051458fc
5 changed files with 35 additions and 38 deletions

View File

@ -2,6 +2,9 @@
Changes between 1.3.4 and 1.4.0.dev0
==================================================
- fix issue109 - sibling conftest.py files will not be loaded.
(and Directory collectors cannot be customized anymore from a Directory's
conftest.py - this needs to happen at least one level up).
- introduce (customizable) assertion failure representations (Floris Bruynooghe)
- nose-plugin: pass through type-signature failures in setup/teardown
functions instead of not calling them (Ed Singleton)

View File

@ -26,7 +26,8 @@ def pytest_runtest_mainloop(session):
return True
def pytest_ignore_collect(path, config):
ignore_paths = config.getconftest_pathlist("collect_ignore", path=path)
p = path.dirpath()
ignore_paths = config.getconftest_pathlist("collect_ignore", path=p)
ignore_paths = ignore_paths or []
excludeopt = config.getvalue("ignore")
if excludeopt:
@ -34,10 +35,6 @@ def pytest_ignore_collect(path, config):
return path in ignore_paths
def pytest_collect_directory(path, parent):
# XXX reconsider the following comment
# not use parent.Directory here as we generally
# want dir/conftest.py to be able to
# define Directory(dir) already
if not parent.recfilter(path): # by default special ".cvs", ...
# check if cmdline specified this dir or a subdir directly
for arg in parent.collection._argfspaths:
@ -45,8 +42,7 @@ def pytest_collect_directory(path, parent):
break
else:
return
Directory = parent.config._getcollectclass('Directory', path)
return Directory(path, parent=parent)
return parent.Directory(path, parent=parent)
def pytest_report_iteminfo(item):
return item.reportinfo()

View File

@ -44,8 +44,9 @@ 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(lambda x: x.check(dir=1, dotfile=0)):
self.getconftestmodules(x)
for x in anchor.listdir("test*"):
if x.check(dir=1):
self.getconftestmodules(x)
break
else:
assert 0, "no root of filesystem?"

View File

@ -163,34 +163,31 @@ class TestGeneralUsage:
result = testdir.runpython(p, prepend=False)
assert not result.ret
@py.test.mark.xfail(reason="http://bitbucket.org/hpk42/py-trunk/issue/109")
def test_sibling_conftest_issue109(self, testdir):
"""
This test is to make sure that the conftest.py of sibling directories is not loaded
if py.test is run for/in one of the siblings directory and those sibling directories
are not packaged together with an __init__.py. See bitbucket issue #109.
"""
for dirname in ['a', 'b']:
testdir.tmpdir.ensure(dirname, dir=True)
testdir.tmpdir.ensure(dirname, '__init__.py')
def test_issue109_sibling_conftests_not_loaded(self, testdir):
sub1 = testdir.tmpdir.mkdir("sub1")
sub2 = testdir.tmpdir.mkdir("sub2")
sub1.join("conftest.py").write("assert 0")
result = testdir.runpytest(sub2)
assert result.ret == 0
sub2.ensure("__init__.py")
p = sub2.ensure("test_hello.py")
result = testdir.runpytest(p)
assert result.ret == 0
result = testdir.runpytest(sub1)
assert result.ret != 0
# To create the conftest.py I would like to use testdir.make*-methods
# but as far as I have seen they can only create files in testdir.tempdir
# Maybe there is a way to explicitly specifiy the directory on which those
# methods work or a completely better way to do that?
backupTmpDir = testdir.tmpdir
testdir.tmpdir = testdir.tmpdir.join(dirname)
testdir.makeconftest("""
_DIR_NAME = '%s'
def pytest_configure(config):
if config.args and config.args[0] != _DIR_NAME:
raise Exception("py.test run for '" + config.args[0] + "', but '" + _DIR_NAME + "/conftest.py' loaded.")
""" % dirname)
testdir.tmpdir = backupTmpDir
for dirname, other_dirname in [('a', 'b'), ('b', 'a')]:
result = testdir.runpytest(dirname)
assert result.ret == 0, "test_sibling_conftest: py.test run for '%s', but '%s/conftest.py' loaded." % (dirname, other_dirname)
def test_directory_skipped(self, testdir):
testdir.makeconftest("""
import py
def pytest_ignore_collect():
py.test.skip("intentional")
""")
testdir.makepyfile("def test_hello(): pass")
result = testdir.runpytest()
assert result.ret == 0
result.stdout.fnmatch_lines([
"*1 skipped*"
])
def test_multiple_items_per_collector_byid(self, testdir):
c = testdir.makeconftest("""

View File

@ -33,7 +33,7 @@ class TestConftestValueAccessGlobal:
conftest = Conftest(onimport=l.append)
conftest.setinitial([basedir.join("adir"),
'--confcutdir=%s' % basedir])
assert len(l) == 2
assert len(l) == 1
assert conftest.rget("a") == 1
assert conftest.rget("b", basedir.join("adir", "b")) == 2
assert len(l) == 2
@ -170,7 +170,7 @@ def test_setinitial_conftest_subdirs(testdir, name):
subconftest = sub.ensure("conftest.py")
conftest = Conftest()
conftest.setinitial([sub.dirpath(), '--confcutdir=%s' % testdir.tmpdir])
if name != ".dotdir":
if name not in ('whatever', '.dotdir'):
assert subconftest in conftest._conftestpath2mod
assert len(conftest._conftestpath2mod) == 1
else: