From c1ac3c08dc9b4ffb2b31293fb7421132000770f3 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 18 Jan 2010 00:41:38 +0100 Subject: [PATCH] do rsync-reporting in the plugin, directly to the terminalreporter if available. --- testing/test_dsession.py | 27 +++++++++++++++++++++++++++ xdist/dsession.py | 22 +++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/testing/test_dsession.py b/testing/test_dsession.py index 872c14d..d8d6962 100644 --- a/testing/test_dsession.py +++ b/testing/test_dsession.py @@ -383,6 +383,33 @@ class TestDSession: assert node.gateway.spec.popen #XXX eq.geteventargs("pytest_sessionfinish") + def test_rsync_printing(self, testdir, linecomp): + config = testdir.parseconfig() + from py._plugin.pytest_terminal import TerminalReporter + rep = TerminalReporter(config, file=linecomp.stringio) + config.pluginmanager.register(rep, "terminalreporter") + dsession = DSession(config) + class gw1: + id = "X1" + spec = execnet.XSpec("popen") + class gw2: + id = "X2" + spec = execnet.XSpec("popen") + #class rinfo: + # version_info = (2, 5, 1, 'final', 0) + # executable = "hello" + # platform = "xyz" + # cwd = "qwe" + + #dsession.pytest_gwmanage_newgateway(gw1, rinfo) + #linecomp.assert_contains_lines([ + # "*X1*popen*xyz*2.5*" + #]) + dsession.pytest_gwmanage_rsyncstart(source="hello", gateways=[gw1, gw2]) + linecomp.assert_contains_lines([ + "[X1,X2] rsyncing: hello", + ]) + def test_collected_function_causes_remote_skip(testdir): sub = testdir.mkpydir("testing") sub.join("test_module.py").write(py.code.Source(""" diff --git a/xdist/dsession.py b/xdist/dsession.py index 46fc0fb..f3b6bdf 100644 --- a/xdist/dsession.py +++ b/xdist/dsession.py @@ -70,22 +70,38 @@ class DSession(Session): self.node2pending = {} self.item2nodes = {} super(DSession, self).__init__(config=config) + try: + self.terminal = config.pluginmanager.getplugin("terminalreporter") + except KeyError: + self.terminal = None + + def report_line(self, line): + if self.terminal: + self.terminal.write_line(line) + + def pytest_gwmanage_rsyncstart(self, source, gateways): + targets = ",".join([gw.id for gw in gateways]) + msg = "[%s] rsyncing: %s" %(targets, source) + self.report_line(msg) + + #def pytest_gwmanage_rsyncfinish(self, source, gateways): + # targets = ", ".join(["[%s]" % gw.id for gw in gateways]) + # self.write_line("rsyncfinish: %s -> %s" %(source, targets)) def main(self, colitems): self.sessionstarts() self.setup() allitems = self.collect_all_items(colitems) self.nodemanager.wait_nodesready(5.0) - #for x in allitems: - # print x.listnames() exitstatus = self.loop(allitems) self.teardown() self.sessionfinishes(exitstatus=exitstatus) return exitstatus def collect_all_items(self, colitems): + self.report_line("[master] starting full item collection ...") allitems = list(self.collect(colitems)) - print ("collected %d items" %(len(allitems))) + self.report_line("[master] collected %d items" %(len(allitems))) return allitems def loop_once(self, loopstate):