[svn r38097] streamline boxed test configuration:

"config.option.boxed"  indicates now boxed tests
and RSession.fixoptions takes care to honour
dist_boxed accordingly.  So you can do

    if not py.test.config.boxed:
        py.test.skip(...)

i also fixed the documentation.

--HG--
branch : trunk
This commit is contained in:
hpk 2007-02-07 19:43:23 +01:00
parent ae9ffd2c19
commit 77b8a010c5
8 changed files with 48 additions and 37 deletions

View File

@ -461,8 +461,8 @@ experimental options
Run browser (implies --startserver). Run browser (implies --startserver).
``--box`` ``--boxed``
Use boxing: run each test in an external process. Very useful for testing Use boxed tests: run each test in an external process. Very useful for testing
things that occasionally segfault (since normally the segfault then would things that occasionally segfault (since normally the segfault then would
stop the whole test process). stop the whole test process).
@ -553,7 +553,7 @@ The options that you need to specify in that conftest.py file are:
* `dist_rsync_ignore` - a list of relative locations to ignore for rsyncing * `dist_rsync_ignore` - a list of relative locations to ignore for rsyncing
* `dist_remotepython` - the remote python executable to run. * `dist_remotepython` - the remote python executable to run.
* `dist_nicelevel` - process priority of remote nodes. * `dist_nicelevel` - process priority of remote nodes.
* `dist_boxing` - will run each single test in a separate process * `dist_boxed` - will run each single test in a separate process
(allowing to survive segfaults for example) (allowing to survive segfaults for example)
* `dist_taskspernode` - Maximum number of tasks being queued to remote nodes * `dist_taskspernode` - Maximum number of tasks being queued to remote nodes
@ -563,7 +563,7 @@ Sample configuration::
dist_rsync_roots = ['../pypy', '../py'] dist_rsync_roots = ['../pypy', '../py']
dist_remotepython = 'python2.4' dist_remotepython = 'python2.4'
dist_nicelevel = 10 dist_nicelevel = 10
dist_boxing = True dist_boxed = False
dist_maxwait = 100 dist_maxwait = 100
dist_taskspernode = 10 dist_taskspernode = 10

View File

@ -261,8 +261,8 @@ class TestExecution(LocalSetup):
assert not numdir.new(ext=str(i-3)).check() assert not numdir.new(ext=str(i-3)).check()
def test_locked_make_numbered_dir(self): def test_locked_make_numbered_dir(self):
if py.test.config.is_boxed(): if py.test.config.option.boxed:
py.test.skip("Fails under boxing") py.test.skip("Fails when run as boxed tests")
root = self.tmpdir root = self.tmpdir
for i in range(10): for i in range(10):
numdir = local.make_numbered_dir(prefix='base.', rootdir=root, numdir = local.make_numbered_dir(prefix='base.', rootdir=root,

View File

@ -156,13 +156,13 @@ class Config(object):
if self.option.dist: if self.option.dist:
name = 'RSession' name = 'RSession'
else: else:
optnames = 'startserver runbrowser apigen restreport boxing'.split() optnames = 'startserver runbrowser apigen restreport boxed'.split()
for opt in optnames: for opt in optnames:
if getattr(self.option, opt, False): if getattr(self.option, opt, False):
name = 'LSession' name = 'LSession'
break break
else: else:
if self.getvalue('dist_boxing'): if self.getvalue('dist_boxed'):
name = 'LSession' name = 'LSession'
if self.option.looponfailing: if self.option.looponfailing:
name = 'RemoteTerminalSession' name = 'RemoteTerminalSession'
@ -170,10 +170,6 @@ class Config(object):
name = 'RemoteTerminalSession' name = 'RemoteTerminalSession'
return name return name
def is_boxed(self):
# XXX probably not a good idea to have this special function ...
return self.option.boxing or self.getvalue("dist_boxing")
def _reparse(self, args): def _reparse(self, args):
""" this is used from tests that want to re-invoke parse(). """ """ this is used from tests that want to re-invoke parse(). """
#assert args # XXX should not be empty #assert args # XXX should not be empty

View File

@ -19,7 +19,7 @@ additionalinfo = None
# whole pkgdir will be rsynced # whole pkgdir will be rsynced
dist_remotepython = "python" dist_remotepython = "python"
dist_taskspernode = 15 dist_taskspernode = 15
dist_boxing = False dist_boxed = False
if hasattr(py.std.os, 'nice'): if hasattr(py.std.os, 'nice'):
dist_nicelevel = py.std.os.nice(0) # nice py.test works dist_nicelevel = py.std.os.nice(0) # nice py.test works
else: else:
@ -87,9 +87,9 @@ def adddefaultoptions(config):
action="store_true", dest="runbrowser", default=False, action="store_true", dest="runbrowser", default=False,
help="run browser (implies --startserver)." help="run browser (implies --startserver)."
), ),
Option('', '--box', Option('', '--boxed',
action="store_true", dest="boxing", action="store_true", dest="boxed", default=False,
help="use boxing (running each test in external process)"), help="box each test run in a separate process"),
Option('', '--rest', Option('', '--rest',
action='store_true', dest="restreport", default=False, action='store_true', dest="restreport", default=False,
help="restructured text output reporting."), help="restructured text output reporting."),

View File

@ -30,6 +30,8 @@ class AbstractSession(Session):
if option.nocapture: if option.nocapture:
print "Cannot use nocapture with distributed testing" print "Cannot use nocapture with distributed testing"
sys.exit(1) sys.exit(1)
if self.config.getvalue("dist_boxed"):
option.boxed = True
super(AbstractSession, self).fixoptions() super(AbstractSession, self).fixoptions()
def init_reporter(self, reporter, hosts, reporter_class, arg=""): def init_reporter(self, reporter, hosts, reporter_class, arg=""):
@ -240,9 +242,8 @@ class LSession(AbstractSession):
module_name=pkgname) module_name=pkgname)
self.tracer = Tracer(self.docstorage) self.tracer = Tracer(self.docstorage)
return apigen_runner return apigen_runner
elif self.config.option.boxed:
return box_runner
else: else:
if (self.config.getvalue('dist_boxing') or self.config.option.boxing)\
and not self.config.option.nocapture:
return box_runner
return plain_runner return plain_runner

View File

@ -7,6 +7,10 @@ def setup_module(mod):
mod.datadir = setupdatadir() mod.datadir = setupdatadir()
mod.tmpdir = py.test.ensuretemp('test_collect') mod.tmpdir = py.test.ensuretemp('test_collect')
def skipboxed():
if py.test.config.option.boxed:
py.test.skip("test does not work with boxed tests")
def test_failing_import_execfile(): def test_failing_import_execfile():
dest = datadir / 'failingimport.py' dest = datadir / 'failingimport.py'
col = py.test.collect.Module(dest) col = py.test.collect.Module(dest)
@ -267,8 +271,7 @@ def test_custom_NONpython_collection_from_conftest():
assert len(l) == 1 assert len(l) == 1
def test_order_of_execution_generator_same_codeline(): def test_order_of_execution_generator_same_codeline():
if py.test.config.is_boxed(): skipboxed()
py.test.skip("Does not work with boxing")
test_list = [] test_list = []
expected_list = range(6) expected_list = range(6)
@ -286,8 +289,7 @@ def test_order_of_execution_generator_same_codeline():
def test_order_of_execution_generator_different_codeline(): def test_order_of_execution_generator_different_codeline():
if py.test.config.is_boxed(): skipboxed()
py.test.skip("Does not work with boxing")
test_list = [] test_list = []
expected_list = range(3) expected_list = range(3)

View File

@ -207,7 +207,7 @@ class TestSessionAndOptions:
assert config._getsessionname() == 'RSession' assert config._getsessionname() == 'RSession'
def test_implied_lsession(self): def test_implied_lsession(self):
optnames = 'startserver runbrowser apigen=x rest box'.split() optnames = 'startserver runbrowser apigen=x rest boxed'.split()
for x in optnames: for x in optnames:
config = py.test.config._reparse([self.tmpdir, '--%s' % x]) config = py.test.config._reparse([self.tmpdir, '--%s' % x])
assert config._getsessionname() == 'LSession' assert config._getsessionname() == 'LSession'
@ -240,22 +240,30 @@ class TestSessionAndOptions:
session = config.initsession() session = config.initsession()
assert session.config is config assert session.config is config
def test_boxing_options(self): def test_boxed_option_including_implied_from_conftest(self):
# XXX config.is_boxed() is probably not a good idea self.tmpdir.join("conftest.py").write("dist_hosts=[]")
tmpdir = self.tmpdir tmpdir = self.tmpdir.ensure("subdir", dir=1)
config = py.test.config._reparse([tmpdir]) config = py.test.config._reparse([tmpdir])
assert not config.option.boxing config.initsession()
assert not config.is_boxed() assert not config.option.boxed
config = py.test.config._reparse(['--dist', tmpdir])
config.initsession()
assert not config.option.boxed
#tmpdir.join("conftest.py").write("dist_boxing=True\n") tmpdir.join("conftest.py").write(py.code.Source("""
#config = py.test.config._reparse([tmpdir]) dist_hosts = []
#assert config.is_boxed() dist_boxed = True
"""))
tmpdir.join("conftest.py").write("dist_boxing=False\n") config = py.test.config._reparse(['--dist', tmpdir])
config = py.test.config._reparse([tmpdir]) config.initsession()
assert not config.is_boxed() assert config.option.boxed
tmpdir.join("conftest.py").write(py.code.Source("""
dist_boxed = False
"""))
config = py.test.config._reparse([tmpdir, '--box']) config = py.test.config._reparse([tmpdir, '--box'])
assert config.is_boxed() assert config.option.boxed
config.initsession()
assert config.option.boxed
def test_getvalue_pathlist(self): def test_getvalue_pathlist(self):
tmpdir = self.tmpdir tmpdir = self.tmpdir

View File

@ -50,6 +50,10 @@ def runfiletest(opts):
l = session.getitemoutcomepairs(Passed) l = session.getitemoutcomepairs(Passed)
assert not l assert not l
def test_is_not_boxed_by_default():
config = py.test.config._reparse([datadir])
assert not config.option.boxed
class TestKeywordSelection: class TestKeywordSelection:
def test_select_simple(self): def test_select_simple(self):
for keyword in ['test_one', 'est_on']: for keyword in ['test_one', 'est_on']: