* introduce progress-reporting

* rename somewhat internal pytest_gwmanage_* events to pytest_xdist_*
* make gateway setup a separate step
This commit is contained in:
holger krekel
2010-11-22 15:39:56 +01:00
parent 9108790801
commit fc1f29db68
7 changed files with 78 additions and 42 deletions

View File

@@ -166,6 +166,9 @@ class DSession:
self.terminal = config.pluginmanager.getplugin("terminalreporter")
except KeyError:
self.terminal = None
else:
self.trdist = TerminalDistReporter(config)
config.pluginmanager.register(self.trdist, "terminaldistreporter")
def report_line(self, line):
if self.terminal and self.config.option.verbose >= 0:
@@ -173,9 +176,6 @@ class DSession:
@pytest.mark.trylast
def pytest_sessionstart(self, session):
if self.config.option.verbose > 0:
self.report_line("instantiating gateways (use -v for details): %s" %
",".join(self.config.option.tx))
self.nodemanager = NodeManager(self.config)
self.nodemanager.setup_nodes(putevent=self.queue.put)
@@ -262,10 +262,15 @@ class DSession:
def slave_collectionfinish(self, node, ids):
self.sched.addnode_collection(node, ids)
self.report_line("[%s] collected %d test items" %(
node.gateway.id, len(ids)))
if self.terminal:
self.trdist.setstatus(node.gateway.spec, "[%d]" %(len(ids)))
if self.sched.collection_is_completed:
if self.terminal:
self.terminal.write_line("")
self.terminal.write_line("scheduling tests via %s" %(
self.sched.__class__.__name__))
self.sched.init_distribute()
def slave_logstart(self, node, nodeid, location):
@@ -316,16 +321,43 @@ class TerminalDistReporter:
def __init__(self, config):
self.config = config
self.tr = config.pluginmanager.getplugin("terminalreporter")
self._status = {}
self._lastlen = 0
def write_line(self, msg):
self.tr.write_line(msg)
def pytest_gwmanage_newgateway(self, gateway):
rinfo = gateway._rinfo()
if self.config.option.verbose >= 0:
version = "%s.%s.%s" %rinfo.version_info[:3]
self.write_line("[%s] %s Python %s cwd: %s" % (
gateway.id, rinfo.platform, version, rinfo.cwd))
def setstatus(self, spec, status, show=True):
self._status[spec.id] = status
if show:
parts = ["%s %s" %(spec.id, self._status[spec.id])
for spec in self._specs]
line = " / ".join(parts)
self.rewrite(line)
def rewrite(self, line, newline=False):
pline = line + " " * max(self._lastlen-len(line), 0)
if newline:
self._lastlen = 0
pline += "\n"
else:
self._lastlen = len(line)
self.tr.rewrite(pline, bold=True)
def pytest_xdist_setupnodes(self, specs):
self._specs = specs
for spec in specs:
self.setstatus(spec, "initializing", show=False)
self.setstatus(spec, "initializing", show=True)
def pytest_xdist_newgateway(self, gateway):
if self.config.option.verbose > 0:
rinfo = gateway._rinfo()
version = "%s.%s.%s" % rinfo.version_info[:3]
self.rewrite("[%s] %s Python %s cwd: %s" % (
gateway.id, rinfo.platform, version, rinfo.cwd),
newline=True)
self.setstatus(gateway.spec, "collecting")
def pytest_testnodeready(self, node):
if self.config.option.verbose > 0:
@@ -333,18 +365,19 @@ class TerminalDistReporter:
infoline = "[%s] Python %s" %(
d['id'],
d['version'].replace('\n', ' -- '),)
self.write_line(infoline)
self.rewrite(infoline, newline=True)
self.setstatus(node.gateway.spec, "ready")
def pytest_testnodedown(self, node, error):
if not error:
return
self.write_line("[%s] node down: %s" %(node.gateway.id, error))
#def pytest_gwmanage_rsyncstart(self, source, gateways):
#def pytest_xdist_rsyncstart(self, source, gateways):
# targets = ",".join([gw.id for gw in gateways])
# msg = "[%s] rsyncing: %s" %(targets, source)
# self.write_line(msg)
#def pytest_gwmanage_rsyncfinish(self, source, gateways):
#def pytest_xdist_rsyncfinish(self, source, gateways):
# targets = ", ".join(["[%s]" % gw.id for gw in gateways])
# self.write_line("rsyncfinish: %s -> %s" %(source, targets))

View File

@@ -1,11 +1,14 @@
def pytest_gwmanage_newgateway(gateway):
def pytest_xdist_setupnodes(config, specs):
""" called before any remote node is set up. """
def pytest_xdist_newgateway(gateway):
""" called on new raw gateway creation. """
def pytest_gwmanage_rsyncstart(source, gateways):
def pytest_xdist_rsyncstart(source, gateways):
""" called before rsyncing a directory to remote gateways takes place. """
def pytest_gwmanage_rsyncfinish(source, gateways):
def pytest_xdist_rsyncfinish(source, gateways):
""" called after rsyncing a directory to remote gateways takes place. """
def pytest_configure_node(node):

View File

@@ -59,12 +59,9 @@ def pytest_cmdline_main(config):
def pytest_configure(config, __multicall__):
__multicall__.execute()
if config.getvalue("dist") != "no":
from xdist.dsession import DSession, TerminalDistReporter
from xdist.dsession import DSession
session = DSession(config)
config.pluginmanager.register(session, "dsession")
trdist = TerminalDistReporter(config)
config.pluginmanager.register(trdist, "terminaldistreporter")
def check_options(config):
if config.option.numprocesses:

View File

@@ -20,20 +20,17 @@ class NodeManager(object):
spec = execnet.XSpec(spec)
if not spec.chdir and not spec.popen:
spec.chdir = defaultchdir
self.group.allocate_id(spec)
self.specs.append(spec)
self.roots = self._getrsyncdirs()
def config_getignores(self):
return self.config.getini("rsyncignore")
def rsync_roots(self):
""" make sure that all remote gateways
have the same set of roots in their
current directory.
"""
self.makegateways()
options = {
'ignores': self.config_getignores(),
'ignores': self.config.getini("rsyncignore"),
'verbose': self.config.option.verbose,
}
if self.roots:
@@ -42,13 +39,15 @@ class NodeManager(object):
self.rsync(root, **options)
def makegateways(self):
self.trace("making gateways")
assert not list(self.group)
self.config.hook.pytest_xdist_setupnodes(config=self.config,
specs=self.specs)
for spec in self.specs:
gw = self.group.makegateway(spec)
self.config.hook.pytest_gwmanage_newgateway(gateway=gw)
self.config.hook.pytest_xdist_newgateway(gateway=gw)
def setup_nodes(self, putevent):
self.makegateways()
self.rsync_roots()
self.trace("setting up nodes")
for gateway in self.group:
@@ -122,12 +121,12 @@ class NodeManager(object):
seen.add(spec)
gateways.append(gateway)
if seen:
self.config.hook.pytest_gwmanage_rsyncstart(
self.config.hook.pytest_xdist_rsyncstart(
source=source,
gateways=gateways,
)
rsync.send()
self.config.hook.pytest_gwmanage_rsyncfinish(
self.config.hook.pytest_xdist_rsyncfinish(
source=source,
gateways=gateways,
)