From 4cd76363f6ba1d08f33a98f8cd9d0dff8f1a4d6b Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 1 Nov 2010 00:27:43 +0100 Subject: [PATCH] adapt to new pytest changes, use new addini/getini methods for rsyncdirs / rsyncignore options --- CHANGELOG | 4 +++- testing/test_slavemanage.py | 12 +++++++----- xdist/dsession.py | 12 ++++++------ xdist/looponfail.py | 2 +- xdist/plugin.py | 20 +++++++++++++------- xdist/remote.py | 6 +++--- xdist/slavemanage.py | 10 +++++----- 7 files changed, 38 insertions(+), 28 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b446b70..100768a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,9 @@ 1.5a1 ------------------------- - +- adapt to pytest-2.0 changes, rsyncdirs and rsyncignore can now + only be specified in [pytest] sections of ini files, see "py.test -h" + for details. - major internal refactoring to match the py-1.4 event refactoring - perform test collection always at slave side instead of at the master - make python2/python3 bridging work, remove usage of pickling diff --git a/testing/test_slavemanage.py b/testing/test_slavemanage.py index 42f9f78..6a784fe 100644 --- a/testing/test_slavemanage.py +++ b/testing/test_slavemanage.py @@ -173,8 +173,9 @@ class TestNodeManager: source.ensure("dir1", "somefile", dir=1) dir2.ensure("hello") source.ensure("bogusdir", "file") - source.join("conftest.py").write(py.code.Source(""" - rsyncdirs = ['dir1/dir2'] + source.join("tox.ini").write(py.std.textwrap.dedent(""" + [pytest] + rsyncdirs=dir1/dir2 """)) config = testdir.reparseconfig([source]) nodemanager = NodeManager(config, ["popen//chdir=%s" % dest]) @@ -189,9 +190,10 @@ class TestNodeManager: dir5 = source.ensure("dir5", "dir6", "bogus") dirf = source.ensure("dir5", "file") dir2.ensure("hello") - source.join("conftest.py").write(py.code.Source(""" - rsyncdirs = ['dir1', 'dir5'] - rsyncignore = ['dir1/dir2', 'dir5/dir6'] + source.join("tox.ini").write(py.std.textwrap.dedent(""" + [pytest] + rsyncdirs = dir1 dir5 + rsyncignore = dir1/dir2 dir5/dir6 """)) config = testdir.reparseconfig([source]) nodemanager = NodeManager(config, ["popen//chdir=%s" % dest]) diff --git a/xdist/dsession.py b/xdist/dsession.py index 416d150..3a58822 100644 --- a/xdist/dsession.py +++ b/xdist/dsession.py @@ -168,12 +168,12 @@ class DSession: self.terminal = None def report_line(self, line): - if self.terminal: + if self.terminal and self.config.option.verbose >= 0: self.terminal.write_line(line) def pytest_sessionstart(self, session, __multicall__): #print "remaining multicall methods", __multicall__.methods - if not self.config.getvalue("verbose"): + 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) @@ -183,11 +183,11 @@ class DSession: """ teardown any resources after a test run. """ self.nodemanager.teardown_nodes() - def pytest_perform_collection(self, __multicall__): + def pytest_collection(self, __multicall__): # prohibit collection of test items in master process __multicall__.methods[:] = [] - def pytest_runtest_mainloop(self): + def pytest_runtestloop(self): numnodes = len(self.nodemanager.gwmanager.specs) dist = self.config.getvalue("dist") if dist == "load": @@ -316,13 +316,13 @@ class TerminalDistReporter: def pytest_gwmanage_newgateway(self, gateway): rinfo = gateway._rinfo() - if self.config.getvalue("verbose"): + 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 pytest_testnodeready(self, node): - if self.config.getvalue("verbose"): + if self.config.option.verbose >= 0: d = node.slaveinfo infoline = "[%s] Python %s" %( d['id'], diff --git a/xdist/looponfail.py b/xdist/looponfail.py index da76e96..ec51e62 100644 --- a/xdist/looponfail.py +++ b/xdist/looponfail.py @@ -145,7 +145,7 @@ class SlaveFailSession: if self.config.option.debug: print(" ".join(map(str, args))) - def pytest_perform_collection(self, session): + def pytest_collection(self, session): self.session = session self.collection = session.collection self.topdir, self.trails = self.current_command diff --git a/xdist/plugin.py b/xdist/plugin.py index 7d62cee..600def8 100644 --- a/xdist/plugin.py +++ b/xdist/plugin.py @@ -126,17 +126,18 @@ put options values in a ``conftest.py`` file like this:: Any commandline ``--tx`` specifictions will add to the list of available execution environments. -Specifying "rsync" dirs in a conftest.py -+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +Specifying "rsync" dirs in a setup.cfg|tox.ini ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -In your ``mypkg/conftest.py`` you may specify directories to synchronise -or to exclude:: +In a ``tox.ini`` or ``setup.cfg`` file in your root project directory +you may specify directories to include or to exclude in synchronisation:: - rsyncdirs = ['.', '../plugins'] - rsyncignore = ['_cache'] + [pytest] + rsyncdirs = . mypkg helperpkg + rsyncignore = .hg These directory specifications are relative to the directory -where the ``conftest.py`` is found. +where the configuration file was found. """ @@ -173,6 +174,11 @@ def pytest_addoption(parser): group.addoption('--rsyncdir', action="append", default=[], metavar="dir1", help="add directory for rsyncing to remote tx nodes.") + parser.addini('rsyncdirs', 'list of (relative) paths to be rsynced for' + ' remote distributed testing.', type="pathlist") + parser.addini('rsyncignore', 'list of (relative) paths to be ignored ' + 'for rsyncing.', type="pathlist") + # ------------------------------------------------------------------------- # distributed testing hooks # ------------------------------------------------------------------------- diff --git a/xdist/remote.py b/xdist/remote.py index ee2a853..90ea933 100644 --- a/xdist/remote.py +++ b/xdist/remote.py @@ -42,10 +42,10 @@ class SlaveInteractor: self.sendevent("slavefinished", slaveoutput=self.config.slaveoutput) return res - def pytest_perform_collection(self, session): + def pytest_collection(self, session): self.sendevent("collectionstart") - def pytest_runtest_mainloop(self, session): + def pytest_runtestloop(self, session): self.log("entering main loop") while 1: name, kwargs = self.channel.receive() @@ -62,7 +62,7 @@ class SlaveInteractor: break return True - def pytest_log_finishcollection(self, collection): + def pytest_collection_finish(self, collection): ids = [collection.getid(item) for item in collection.items] self.sendevent("collectionfinish", topdir=str(collection.topdir), diff --git a/xdist/slavemanage.py b/xdist/slavemanage.py index a97e78a..4bc2a8d 100644 --- a/xdist/slavemanage.py +++ b/xdist/slavemanage.py @@ -1,4 +1,4 @@ -import py +import py, pytest import sys, os import execnet import xdist.remote @@ -18,7 +18,7 @@ class NodeManager(object): self.config.hook.pytest_trace(category="nodemanage", msg=msg) def config_getignores(self): - return self.config.getconftest_pathlist("rsyncignore") + return self.config.getini("rsyncignore") def rsync_roots(self): """ make sure that all remote gateways @@ -78,7 +78,7 @@ class NodeManager(object): else: xspeclist.extend([xspec[i+1:]] * num) if not xspeclist: - raise config.Error( + raise pytest.UsageError( "MISSING test execution (tx) nodes: please specify --tx") return [execnet.XSpec(x) for x in xspeclist] @@ -86,14 +86,14 @@ class NodeManager(object): config = self.config candidates = [py._pydir] candidates += config.option.rsyncdir - conftestroots = config.getconftest_pathlist("rsyncdirs") + conftestroots = config.getini("rsyncdirs") if conftestroots: candidates.extend(conftestroots) roots = [] for root in candidates: root = py.path.local(root).realpath() if not root.check(): - raise config.Error("rsyncdir doesn't exist: %r" %(root,)) + raise pytest.UsageError("rsyncdir doesn't exist: %r" %(root,)) if root not in roots: roots.append(root) return roots