diff --git a/py/doc/test-dist.txt b/py/doc/test-dist.txt index 11311550f..48b835923 100644 --- a/py/doc/test-dist.txt +++ b/py/doc/test-dist.txt @@ -27,7 +27,11 @@ To send tests to a python2.4 process, you may type:: This will start a subprocess which is run with the "python2.4" Python interpreter, found in your system binary lookup path. -.. For convenience you may prepend ``3*`` to create three sub processes. +If you prefix the --tx option like this:: + + py.test --tx 3*popen//python=python2.4 + +then three subprocesses would be created. Sending tests to remote SSH accounts diff --git a/py/test/config.py b/py/test/config.py index 5f44341bd..ef7af93a0 100644 --- a/py/test/config.py +++ b/py/test/config.py @@ -255,15 +255,20 @@ class Config(object): def getxspecs(self): config = self if config.option.numprocesses: - xspec = ['popen'] * config.option.numprocesses + xspeclist = ['popen'] * config.option.numprocesses else: - xspec = config.option.xspec - if not xspec: - xspec = config.getvalue("xspec") - if xspec is None: + xspeclist = [] + for xspec in config.getvalue("tx"): + i = xspec.find("*") + try: + num = int(xspec[:i]) + except ValueError: + xspeclist.append(xspec) + else: + xspeclist.extend([xspec[i+1:]] * num) + if not xspeclist: raise config.Error("MISSING test execution (tx) nodes: please specify --tx") - #print "option value for xspecs", xspec - return [py.execnet.XSpec(x) for x in xspec] + return [py.execnet.XSpec(x) for x in xspeclist] def getrsyncdirs(self): config = self diff --git a/py/test/dist/testing/test_functional_dsession.py b/py/test/dist/testing/test_functional_dsession.py index a263379e6..d36d17b18 100644 --- a/py/test/dist/testing/test_functional_dsession.py +++ b/py/test/dist/testing/test_functional_dsession.py @@ -26,7 +26,7 @@ class TestAsyncFunctional: print "test_1: conftest.option.someopt", conftest.option.someopt assert conftest.option.someopt """)) - result = testdir.runpytest('-n1', p1, '--someopt') + result = testdir.runpytest('-d', '--tx=popen', p1, '--someopt') assert result.ret == 0 extra = result.stdout.fnmatch_lines([ "*1 passed*", diff --git a/py/test/dist/testing/test_nodemanage.py b/py/test/dist/testing/test_nodemanage.py index 67a0062f5..8965aa41e 100644 --- a/py/test/dist/testing/test_nodemanage.py +++ b/py/test/dist/testing/test_nodemanage.py @@ -117,39 +117,3 @@ class TestNodeManager: ev = sorter.getfirstnamed("itemtestreport") assert ev.passed -class TestOptionsAndConfiguration: - def test_getxspecs_numprocesses(self, testdir): - config = testdir.parseconfig("-n3") - xspecs = config.getxspecs() - assert len(xspecs) == 3 - - def test_getxspecs(self, testdir): - testdir.chdir() - config = testdir.parseconfig("--tx=popen", "--tx", "ssh=xyz") - xspecs = config.getxspecs() - assert len(xspecs) == 2 - print xspecs - assert xspecs[0].popen - assert xspecs[1].ssh == "xyz" - - def test_getconfigroots(self, testdir): - config = testdir.parseconfig('--rsyncdir=' + str(testdir.tmpdir)) - roots = config.getrsyncdirs() - assert len(roots) == 1 + 1 - assert testdir.tmpdir in roots - - def test_getconfigroots_with_conftest(self, testdir): - testdir.chdir() - p = py.path.local() - for bn in 'x y z'.split(): - p.mkdir(bn) - testdir.makeconftest(""" - rsyncdirs= 'x', - """) - config = testdir.parseconfig(testdir.tmpdir, '--rsyncdir=y', '--rsyncdir=z') - roots = config.getrsyncdirs() - assert len(roots) == 3 + 1 - assert py.path.local('y') in roots - assert py.path.local('z') in roots - assert testdir.tmpdir.join('x') in roots - diff --git a/py/test/plugin/pytest_default.py b/py/test/plugin/pytest_default.py index 0beeeb906..fdc2149b2 100644 --- a/py/test/plugin/pytest_default.py +++ b/py/test/plugin/pytest_default.py @@ -103,7 +103,7 @@ class DefaultPlugin: help="number of local test processes. conflicts with --dist.") group.addoption('--rsyncdir', action="append", default=[], metavar="dir1", help="add local directory for rsync to remote test nodes.") - group._addoption('--tx', dest="xspec", action="append", + group._addoption('--tx', dest="tx", action="append", default=[], help=("add a test environment, specified in XSpec syntax. examples: " "--tx popen//python=python2.5 --tx socket=192.168.1.102")) #group._addoption('--rest', diff --git a/py/test/testing/acceptance_test.py b/py/test/testing/acceptance_test.py index f52252948..81fbdbb3f 100644 --- a/py/test/testing/acceptance_test.py +++ b/py/test/testing/acceptance_test.py @@ -287,7 +287,7 @@ class TestPyTest: """, ) testdir.makeconftest(""" - pytest_option_xspec = 'popen popen popen'.split() + pytest_option_tx = 'popen popen popen'.split() """) result = testdir.runpytest(p1, '-d') result.stdout.fnmatch_lines([ @@ -319,7 +319,7 @@ class TestPyTest: os.kill(os.getpid(), 15) """ ) - result = testdir.runpytest(p1, '-d', '-n 3') + result = testdir.runpytest(p1, '-d', '--tx=3*popen') result.stdout.fnmatch_lines([ "*popen*Python*", "*popen*Python*", diff --git a/py/test/testing/test_config.py b/py/test/testing/test_config.py index 0637158de..5ff646e89 100644 --- a/py/test/testing/test_config.py +++ b/py/test/testing/test_config.py @@ -218,6 +218,48 @@ class TestConfigApi_getcolitems: assert col.config is config +class TestOptionsAndConfiguration: + def test_getxspecs_numprocesses(self, testdir): + config = testdir.parseconfig("-n3") + xspecs = config.getxspecs() + assert len(xspecs) == 3 + + def test_getxspecs(self, testdir): + testdir.chdir() + config = testdir.parseconfig("--tx=popen", "--tx", "ssh=xyz") + xspecs = config.getxspecs() + assert len(xspecs) == 2 + print xspecs + assert xspecs[0].popen + assert xspecs[1].ssh == "xyz" + + def test_xspecs_multiplied(self, testdir): + testdir.chdir() + xspecs = testdir.parseconfig("--tx=3*popen",).getxspecs() + assert len(xspecs) == 3 + assert xspecs[1].popen + + def test_getrsyncdirs(self, testdir): + config = testdir.parseconfig('--rsyncdir=' + str(testdir.tmpdir)) + roots = config.getrsyncdirs() + assert len(roots) == 1 + 1 + assert testdir.tmpdir in roots + + def test_getrsyncdirs_with_conftest(self, testdir): + testdir.chdir() + p = py.path.local() + for bn in 'x y z'.split(): + p.mkdir(bn) + testdir.makeconftest(""" + rsyncdirs= 'x', + """) + config = testdir.parseconfig(testdir.tmpdir, '--rsyncdir=y', '--rsyncdir=z') + roots = config.getrsyncdirs() + assert len(roots) == 3 + 1 + assert py.path.local('y') in roots + assert py.path.local('z') in roots + assert testdir.tmpdir.join('x') in roots + class TestOptionEffects: