deprecate direct definition of Directory, Module, ... in conftest.py's,
add some pytest collect related tests + some refinements. --HG-- branch : trunk
This commit is contained in:
@@ -36,10 +36,10 @@ class Node(object):
|
||||
- configuration/options for setup/teardown
|
||||
stdout/stderr capturing and execution of test items
|
||||
"""
|
||||
def __init__(self, name, parent=None):
|
||||
def __init__(self, name, parent=None, config=None):
|
||||
self.name = name
|
||||
self.parent = parent
|
||||
self.config = getattr(parent, 'config', None)
|
||||
self.config = config or parent.config
|
||||
self.fspath = getattr(parent, 'fspath', None)
|
||||
self.ihook = HookProxy(self)
|
||||
|
||||
@@ -353,9 +353,9 @@ class Collector(Node):
|
||||
return traceback
|
||||
|
||||
class FSCollector(Collector):
|
||||
def __init__(self, fspath, parent=None):
|
||||
def __init__(self, fspath, parent=None, config=None):
|
||||
fspath = py.path.local(fspath)
|
||||
super(FSCollector, self).__init__(fspath.basename, parent)
|
||||
super(FSCollector, self).__init__(fspath.basename, parent, config=config)
|
||||
self.fspath = fspath
|
||||
|
||||
def __getstate__(self):
|
||||
|
||||
@@ -156,16 +156,20 @@ class Config(object):
|
||||
pkgpath = path.pypkgpath()
|
||||
if pkgpath is None:
|
||||
pkgpath = path.check(file=1) and path.dirpath() or path
|
||||
Dir = self._getcollectclass("Directory", pkgpath)
|
||||
col = Dir(pkgpath)
|
||||
col.config = self
|
||||
tmpcol = py.test.collect.Directory(pkgpath, config=self)
|
||||
col = tmpcol.ihook.pytest_collect_directory(path=pkgpath, parent=tmpcol)
|
||||
col.parent = None
|
||||
return col._getfsnode(path)
|
||||
|
||||
def _getcollectclass(self, name, path):
|
||||
try:
|
||||
return self.getvalue(name, path)
|
||||
cls = self.getvalue(name, path)
|
||||
except KeyError:
|
||||
return getattr(py.test.collect, name)
|
||||
else:
|
||||
py.log._apiwarn(">1.1", "%r was found in a conftest.py file, "
|
||||
"use pytest_collect hooks instead." % (cls,))
|
||||
return cls
|
||||
|
||||
def getconftest_pathlist(self, name, path=None):
|
||||
""" return a matching value, which needs to be sequence
|
||||
|
||||
@@ -315,9 +315,9 @@ class Function(FunctionMixin, py.test.collect.Item):
|
||||
and executing a Python callable test object.
|
||||
"""
|
||||
_genid = None
|
||||
def __init__(self, name, parent=None, args=None,
|
||||
def __init__(self, name, parent=None, args=None, config=None,
|
||||
callspec=None, callobj=_dummy):
|
||||
super(Function, self).__init__(name, parent)
|
||||
super(Function, self).__init__(name, parent, config=config)
|
||||
self._args = args
|
||||
if self._isyieldedfunction():
|
||||
assert not callspec, "yielded functions (deprecated) cannot have funcargs"
|
||||
|
||||
@@ -26,6 +26,7 @@ def pytest_unconfigure(config):
|
||||
|
||||
def pytest_collect_directory(path, parent):
|
||||
""" return Collection node or None for the given path. """
|
||||
pytest_collect_directory.firstresult = True
|
||||
|
||||
def pytest_collect_file(path, parent):
|
||||
""" return Collection node or None for the given path. """
|
||||
|
||||
Reference in New Issue
Block a user