[Zope3-checkins] SVN: zope.testing/trunk/ add exit-with-status support

Gary Poster gary at zope.com
Wed Mar 14 15:17:24 EDT 2007


Log message for revision 73174:
  add exit-with-status support

Changed:
  U   zope.testing/trunk/CHANGES.txt
  U   zope.testing/trunk/src/zope/testing/testrunner-errors.txt
  U   zope.testing/trunk/src/zope/testing/testrunner.py

-=-
Modified: zope.testing/trunk/CHANGES.txt
===================================================================
--- zope.testing/trunk/CHANGES.txt	2007-03-14 18:21:28 UTC (rev 73173)
+++ zope.testing/trunk/CHANGES.txt	2007-03-14 19:17:23 UTC (rev 73174)
@@ -7,6 +7,9 @@
 - Fix testrunner-wo-source.txt and testrunner-errors.txt to run with a
   read-only source tree.
 
+- Added exit-with-status support (supports use with buildbot and
+  zc.recipe.testing)
+
 3.0 (2006/09/20)
 ================
 

Modified: zope.testing/trunk/src/zope/testing/testrunner-errors.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-errors.txt	2007-03-14 18:21:28 UTC (rev 73173)
+++ zope.testing/trunk/src/zope/testing/testrunner-errors.txt	2007-03-14 19:17:23 UTC (rev 73174)
@@ -806,6 +806,46 @@
       sample2.sample23.sampletests_i
     True
 
+Reporting Errors to Calling Processes
+-------------------------------------
+
+The testrunner can return an error status, indicating that the tests
+failed.  This can be useful for an invoking process that wants to
+monitor the result of a test run.
+
+To use, specify the argument "--exit-with-status".
+
+    >>> sys.argv = (
+    ...     'test --exit-with-status --tests-pattern ^sampletests_1$'.split())
+    >>> try:
+    ...     testrunner.run(defaults)
+    ... except SystemExit, e:
+    ...     print 'exited with code', e.code
+    ... else:
+    ...     print 'sys.exit was not called'
+    ... # doctest: +ELLIPSIS
+    Running unit tests:
+    ...
+      Ran 1 tests with 1 failures and 0 errors in 0.002 seconds.
+    exited with code 1
+
+A passing test does not exit.
+
+    >>> sys.argv = (
+    ...     'test --exit-with-status --tests-pattern ^sampletests$'.split())
+    >>> try:
+    ...     testrunner.run(defaults)
+    ... except SystemExit, e2:
+    ...     print 'oops'
+    ... else:
+    ...     print 'sys.exit was not called'
+    ... # doctest: +ELLIPSIS
+    Running unit tests:
+    ...
+    Total: 364 tests, 0 failures, 0 errors
+    ...
+    sys.exit was not called
+
 And remove the temporary directory:
 
     >>> shutil.rmtree(tmpdir)

Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py	2007-03-14 18:21:28 UTC (rev 73173)
+++ zope.testing/trunk/src/zope/testing/testrunner.py	2007-03-14 19:17:23 UTC (rev 73174)
@@ -301,6 +301,9 @@
 
     doctest.set_unittest_reportflags(old_reporting_flags)
 
+    if failed and options.exitwithstatus:
+        sys.exit(1)
+
     return failed
 
 def run_with_options(options, found_suites=None):
@@ -1744,6 +1747,13 @@
 compilation to .pyc/.pyo.  Use of this option implies --keepbytecode.
 """)
 
+other.add_option(
+    '--exit-with-status', action="store_true", dest='exitwithstatus',
+    help="""\
+Return an error exit status if the tests failed.  This can be useful for
+an invoking process that wants to monitor the result of a test run.
+""")
+
 parser.add_option_group(other)
 
 ######################################################################



More information about the Zope3-Checkins mailing list