[Zope3-checkins]
SVN: zope.testing/trunk/src/zope/testing/testrunner
Changed the strategy for running layers as subproccesses when
previous
Jim Fulton
jim at zope.com
Tue Jan 3 18:17:02 EST 2006
Log message for revision 41126:
Changed the strategy for running layers as subproccesses when previous
layers can't be torn down. Now, we run each subsequent layer as a
separate subprocess, rather than running all subsequent layers as a
single subprocess. In the later case, if lots of layers can't be torn
down, we end up with deeply nested subprocesses, which isn't
good. Also, now we get output after each subsequent layer, rather than
having to wait until all of the layers have run.
Also made output when laters can't be torn down less chatty.
Changed:
U zope.testing/trunk/src/zope/testing/testrunner-layers-ntd.txt
U zope.testing/trunk/src/zope/testing/testrunner.py
-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner-layers-ntd.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-layers-ntd.txt 2006-01-03 22:31:52 UTC (rev 41125)
+++ zope.testing/trunk/src/zope/testing/testrunner-layers-ntd.txt 2006-01-03 23:17:01 UTC (rev 41126)
@@ -36,12 +36,12 @@
Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
Running sample2.sampletests_ntd.Layer tests:
Tear down sample1.sampletests_ntd.Layer ... not supported
- Running sample2.sampletests_ntd.Layer tests:
+ Running in a subprocess.
Set up sample2.sampletests_ntd.Layer in N.NNN seconds.
Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
- Running sample3.sampletests_ntd.Layer tests:
Tear down sample2.sampletests_ntd.Layer ... not supported
Running sample3.sampletests_ntd.Layer tests:
+ Running in a subprocess.
Set up sample3.sampletests_ntd.Layer in N.NNN seconds.
<BLANKLINE>
<BLANKLINE>
@@ -76,7 +76,6 @@
AssertionError: 1 != 3
<BLANKLINE>
Ran 6 tests with 2 failures and 2 errors in N.NNN seconds.
- Tearing down left over layers:
Tear down sample3.sampletests_ntd.Layer ... not supported
Total: 8 tests, 2 failures, 2 errors
True
@@ -95,12 +94,12 @@
Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
Running sample2.sampletests_ntd.Layer tests:
Tear down sample1.sampletests_ntd.Layer ... not supported
- Running sample2.sampletests_ntd.Layer tests:
+ Running in a subprocess.
Set up sample2.sampletests_ntd.Layer in N.NNN seconds.
Ran 1 tests with 0 failures and 0 errors in N.NNN seconds.
- Running sample3.sampletests_ntd.Layer tests:
Tear down sample2.sampletests_ntd.Layer ... not supported
Running sample3.sampletests_ntd.Layer tests:
+ Running in a subprocess.
Set up sample3.sampletests_ntd.Layer in N.NNN seconds.
<BLANKLINE>
<BLANKLINE>
@@ -155,7 +154,6 @@
**********************************************************************
<BLANKLINE>
Ran 6 tests with 0 failures and 4 errors in N.NNN seconds.
- Tearing down left over layers:
Tear down sample3.sampletests_ntd.Layer ... not supported
Total: 8 tests, 0 failures, 4 errors
True
@@ -170,7 +168,7 @@
Ran 1 tests with 0 failures and 0 errors in 0.000 seconds.
Running sample2.sampletests_ntds.Layer tests:
Tear down sample1.sampletests_ntds.Layer ... not supported
- Running sample2.sampletests_ntds.Layer tests:
+ Running in a subprocess.
Set up sample2.sampletests_ntds.Layer in 0.000 seconds.
--Return--
> testrunner-ex/sample2/sampletests_ntds.py(37)test_something()->None
@@ -236,7 +234,6 @@
**********************************************************************
<BLANKLINE>
Ran 7 tests with 0 failures and 0 errors in 0.008 seconds.
- Tearing down left over layers:
Tear down sample2.sampletests_ntds.Layer ... not supported
Total: 8 tests, 0 failures, 0 errors
False
Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py 2006-01-03 22:31:52 UTC (rev 41125)
+++ zope.testing/trunk/src/zope/testing/testrunner.py 2006-01-03 23:17:01 UTC (rev 41126)
@@ -178,6 +178,7 @@
if len(args) > 1 and args[1] == '--resume-layer':
args.pop(1)
resume_layer = args.pop(1)
+ resume_number = int(args.pop(1))
defaults = []
while len(args) > 1 and args[1] == '--default':
args.pop(1)
@@ -185,7 +186,7 @@
sys.stdin = FakeInputContinueGenerator()
else:
- resume_layer = None
+ resume_layer = resume_number = None
options = get_options(args, defaults)
if options.fail:
@@ -193,6 +194,7 @@
options.testrunner_defaults = defaults
options.resume_layer = resume_layer
+ options.resume_number = resume_number
# Make sure we start with real pdb.set_trace. This is needed
# to make tests of the test runner work properly. :)
@@ -364,38 +366,38 @@
nlayers += 1
ran += run_tests(options, tests, 'unit', failures, errors)
- if options.resume_layer:
- resume = False
- else:
- resume = True
-
setup_layers = {}
- for layer_name, layer, tests in ordered_layers(tests_by_layer_name):
- if options.layer:
- should_run = False
- for pat in options.layer:
- if pat(layer_name):
- should_run = True
- break
- else:
- should_run = True
- if should_run:
- if (not resume) and (layer_name == options.resume_layer):
- resume = True
- if not resume:
- continue
- nlayers += 1
- try:
- ran += run_layer(options, layer_name, layer, tests,
- setup_layers, failures, errors)
- except CanNotTearDown:
- setup_layers = None
- ran += resume_tests(options, layer_name, failures, errors)
+ layers_to_run = list(ordered_layers(tests_by_layer_name))
+ if options.resume_layer is not None:
+ layers_to_run = [
+ (layer_name, layer, tests)
+ for (layer_name, layer, tests) in layers_to_run
+ if layer_name == options.resume_layer
+ ]
+ elif options.layer:
+ layers_to_run = [
+ (layer_name, layer, tests)
+ for (layer_name, layer, tests) in layers_to_run
+ if filter(None, [pat(layer_name) for pat in options.layer])
+ ]
+
+
+ for layer_name, layer, tests in layers_to_run:
+ nlayers += 1
+ try:
+ ran += run_layer(options, layer_name, layer, tests,
+ setup_layers, failures, errors)
+ except CanNotTearDown:
+ setup_layers = None
+ if not options.resume_layer:
+ ran += resume_tests(options, layer_name, layers_to_run,
+ failures, errors)
break
if setup_layers:
- print "Tearing down left over layers:"
+ if options.resume_layer == None:
+ print "Tearing down left over layers:"
tear_down_unneeded((), setup_layers, True)
if options.resume_layer:
@@ -547,56 +549,69 @@
def run_layer(options, layer_name, layer, tests, setup_layers,
failures, errors):
- print "Running %s tests:" % layer_name
gathered = []
gather_layers(layer, gathered)
needed = dict([(l, 1) for l in gathered])
+ if options.resume_number != 0:
+ print "Running %s tests:" % layer_name
tear_down_unneeded(needed, setup_layers)
+ if options.resume_layer != None:
+ print " Running in a subprocess."
+
setup_layer(layer, setup_layers)
return run_tests(options, tests, layer_name, failures, errors)
-def resume_tests(options, layer_name, failures, errors):
- args = [sys.executable,
- options.original_testrunner_args[0],
- '--resume-layer', layer_name,
- ]
- for d in options.testrunner_defaults:
- args.extend(['--default', d])
+def resume_tests(options, layer_name, layers, failures, errors):
+ layers = [l for (l, _, _) in layers]
+ layers = layers[layers.index(layer_name):]
+ rantotal = 0
+ resume_number = 0
+ for layer_name in layers:
+ args = [sys.executable,
+ options.original_testrunner_args[0],
+ '--resume-layer', layer_name, str(resume_number),
+ ]
+ resume_number += 1
+ for d in options.testrunner_defaults:
+ args.extend(['--default', d])
- args.extend(options.original_testrunner_args[1:])
+ args.extend(options.original_testrunner_args[1:])
- # this is because of a bug in Python (http://www.python.org/sf/900092)
- if (hotshot is not None and options.profile
- and sys.version_info[:3] <= (2,4,1)):
- args.insert(1, '-O')
+ # this is because of a bug in Python (http://www.python.org/sf/900092)
+ if (hotshot is not None and options.profile
+ and sys.version_info[:3] <= (2,4,1)):
+ args.insert(1, '-O')
- if sys.platform.startswith('win'):
- args = args[0] + ' ' + ' '.join([
- ('"' + a.replace('\\', '\\\\').replace('"', '\\"') + '"')
- for a in args[1:]
- ])
+ if sys.platform.startswith('win'):
+ args = args[0] + ' ' + ' '.join([
+ ('"' + a.replace('\\', '\\\\').replace('"', '\\"') + '"')
+ for a in args[1:]
+ ])
- subin, subout, suberr = os.popen3(args)
- for l in subout:
- sys.stdout.write(l)
+ subin, subout, suberr = os.popen3(args)
+ for l in subout:
+ sys.stdout.write(l)
- line = suberr.readline()
- try:
- ran, nfail, nerr = map(int, line.strip().split())
- except:
- raise SubprocessError(line+suberr.read())
+ line = suberr.readline()
+ try:
+ ran, nfail, nerr = map(int, line.strip().split())
+ except:
+ raise SubprocessError(line+suberr.read())
- while nfail > 0:
- nfail -= 1
- failures.append((suberr.readline().strip(), None))
- while nerr > 0:
- nerr -= 1
- errors.append((suberr.readline().strip(), None))
- return ran
+ while nfail > 0:
+ nfail -= 1
+ failures.append((suberr.readline().strip(), None))
+ while nerr > 0:
+ nerr -= 1
+ errors.append((suberr.readline().strip(), None))
+ rantotal += ran
+ return rantotal
+
+
class SubprocessError(Exception):
"""An error occurred when running a subprocess
"""
More information about the Zope3-Checkins
mailing list