[Checkins] SVN: zope.testrunner/trunk/ New option: --profile-directory.
Marius Gedminas
cvs-admin at zope.org
Fri Feb 8 10:00:01 UTC 2013
Log message for revision 129213:
New option: --profile-directory.
Use it in the test suite so that tests executed by detox in parallel don't
conflict.
Changed:
U zope.testrunner/trunk/CHANGES.txt
U zope.testrunner/trunk/src/zope/testrunner/options.py
U zope.testrunner/trunk/src/zope/testrunner/profiling.py
U zope.testrunner/trunk/src/zope/testrunner/testrunner-profiling-cprofiler.txt
-=-
Modified: zope.testrunner/trunk/CHANGES.txt
===================================================================
--- zope.testrunner/trunk/CHANGES.txt 2013-02-08 09:20:53 UTC (rev 129212)
+++ zope.testrunner/trunk/CHANGES.txt 2013-02-08 10:00:00 UTC (rev 129213)
@@ -15,7 +15,10 @@
- Fix --shuffle nondeterminism when multiple test layers are present.
Note: this will likely change the order of tests for the same --shuffle-seed.
+- New option: --profile-directory. Use it in the test suite so that tests
+ executed by detox in parallel don't conflict.
+
4.1.0 (2013-02-07)
==================
Modified: zope.testrunner/trunk/src/zope/testrunner/options.py
===================================================================
--- zope.testrunner/trunk/src/zope/testrunner/options.py 2013-02-08 09:20:53 UTC (rev 129212)
+++ zope.testrunner/trunk/src/zope/testrunner/options.py 2013-02-08 10:00:00 UTC (rev 129213)
@@ -318,6 +318,14 @@
Run the tests under cProfiler or hotshot and display the top 50 stats, sorted
by cumulative time and number of calls.
""")
+analysis.add_option(
+ '--profile-directory', action="store", dest='prof_dir', default='.',
+ help="""\
+Directory for temporary profiler files. All files named tests_profile.*.prof
+in this directory will be removed. If you intend to run multiple instances
+of the test runner in parallel, be sure to tell them to use different
+directories, so they won't step on each other's toes.
+""")
def do_pychecker(*args):
if not os.environ.get("PYCHECKER"):
Modified: zope.testrunner/trunk/src/zope/testrunner/profiling.py
===================================================================
--- zope.testrunner/trunk/src/zope/testrunner/profiling.py 2013-02-08 09:20:53 UTC (rev 129212)
+++ zope.testrunner/trunk/src/zope/testrunner/profiling.py 2013-02-08 10:00:00 UTC (rev 129213)
@@ -107,15 +107,16 @@
def global_setup(self):
self.prof_prefix = 'tests_profile.'
self.prof_suffix = '.prof'
- self.prof_glob = self.prof_prefix + '*' + self.prof_suffix
+ self.prof_glob = os.path.join(self.runner.options.prof_dir,
+ self.prof_prefix + '*' + self.prof_suffix)
# if we are going to be profiling, and this isn't a subprocess,
# clean up any stale results files
if not self.runner.options.resume_layer:
for file_name in glob.glob(self.prof_glob):
os.unlink(file_name)
# set up the output file
- self.oshandle, self.file_path = tempfile.mkstemp(self.prof_suffix,
- self.prof_prefix, '.')
+ self.oshandle, self.file_path = tempfile.mkstemp(
+ self.prof_suffix, self.prof_prefix, self.runner.options.prof_dir)
self.profiler = available_profilers[self.runner.options.profile](self.file_path)
# Need to do this rebinding to support the stack-frame annoyance with
Modified: zope.testrunner/trunk/src/zope/testrunner/testrunner-profiling-cprofiler.txt
===================================================================
--- zope.testrunner/trunk/src/zope/testrunner/testrunner-profiling-cprofiler.txt 2013-02-08 09:20:53 UTC (rev 129212)
+++ zope.testrunner/trunk/src/zope/testrunner/testrunner-profiling-cprofiler.txt 2013-02-08 10:00:00 UTC (rev 129213)
@@ -4,13 +4,16 @@
The testrunner includes the ability to profile the test execution with cProfile
via the `--profile=cProfile` option::
- >>> import os.path, sys
+ >>> import os, sys, tempfile
>>> directory_with_tests = os.path.join(this_directory, 'testrunner-ex')
>>> sys.path.append(directory_with_tests)
+ >>> tempdir = tempfile.mkdtemp(prefix='zope.testrunner-')
+
>>> defaults = [
... '--path', directory_with_tests,
... '--tests-pattern', '^sampletestsf?$',
+ ... '--profile-directory', tempdir,
... ]
>>> sys.argv = [testrunner_script, '--profile=cProfile']
@@ -36,14 +39,10 @@
The testrunner creates temnporary files containing cProfiler profiler
data::
- >>> import glob
- >>> files = list(glob.glob('tests_profile.*.prof'))
- >>> files.sort()
- >>> files
+ >>> os.listdir(tempdir)
['tests_profile.cZj2jt.prof', 'tests_profile.yHD-so.prof']
It deletes these when rerun. We'll delete these ourselves::
- >>> import os
- >>> for f in files:
- ... os.unlink(f)
+ >>> import shutil
+ >>> shutil.rmtree(tempdir)
More information about the checkins
mailing list