[Zope3-checkins] SVN: zope.testing/trunk/src/zope/testing/testrunner/ Fix a bug that caused a SubprocessError to be generated if a subprocess

Benji York benji at zope.com
Sat Jul 5 20:04:38 EDT 2008


Log message for revision 88047:
  Fix a bug that caused a SubprocessError to be generated if a subprocess
  sent any output to stderr (deprecation warnings are a common cause).
  

Changed:
  U   zope.testing/trunk/src/zope/testing/testrunner/runner.py
  A   zope.testing/trunk/src/zope/testing/testrunner/testrunner-ex/sample2/stderrtest.py
  U   zope.testing/trunk/src/zope/testing/testrunner/testrunner-layers-ntd.txt

-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner/runner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/runner.py	2008-07-05 21:00:43 UTC (rev 88046)
+++ zope.testing/trunk/src/zope/testing/testrunner/runner.py	2008-07-06 00:04:36 UTC (rev 88047)
@@ -402,15 +402,24 @@
             else:
                 break
 
-        line = suberr.readline()
-        try:
-            ran, nfail, nerr = map(int, line.strip().split())
-        except KeyboardInterrupt:
-            raise
-        except:
-            raise SubprocessError(
-                'No subprocess summary found', line+suberr.read())
+        # The subprocess may have spewed any number of things to stderr, so
+        # we'll keep looking until we find the information we're looking for.
+        whole_suberr = ''
+        while True:
+            line = suberr.readline()
+            whole_suberr += line
+            if not line:
+                raise SubprocessError(
+                    'No subprocess summary found', whole_suberr+suberr.read())
 
+            try:
+                ran, nfail, nerr = map(int, line.strip().split())
+                break
+            except KeyboardInterrupt:
+                raise
+            except:
+                continue
+
         while nfail > 0:
             nfail -= 1
             failures.append((suberr.readline().strip(), None))

Added: zope.testing/trunk/src/zope/testing/testrunner/testrunner-ex/sample2/stderrtest.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-ex/sample2/stderrtest.py	                        (rev 0)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-ex/sample2/stderrtest.py	2008-07-06 00:04:36 UTC (rev 88047)
@@ -0,0 +1,54 @@
+##############################################################################
+#
+# Copyright (c) 2003 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Sample tests with a layer that produces output on stderr
+
+$Id$
+"""
+
+import unittest
+from zope.testing import doctest
+import sys
+
+
+sys.stderr.write('A message on stderr.\n')
+
+
+class Layer:
+
+    def setUp(self):
+        pass
+    setUp = classmethod(setUp)
+
+    def tearDown(self):
+        pass
+    tearDown = classmethod(tearDown)
+
+
+def test_something():
+    """
+    >>> 1 + 1
+    2
+    """
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    d = doctest.DocTestSuite()
+    d.layer = Layer
+    suite.addTest(d)
+    return suite
+
+
+if __name__ == '__main__':
+    unittest.main()


Property changes on: zope.testing/trunk/src/zope/testing/testrunner/testrunner-ex/sample2/stderrtest.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: zope.testing/trunk/src/zope/testing/testrunner/testrunner-layers-ntd.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner/testrunner-layers-ntd.txt	2008-07-05 21:00:43 UTC (rev 88046)
+++ zope.testing/trunk/src/zope/testing/testrunner/testrunner-layers-ntd.txt	2008-07-06 00:04:36 UTC (rev 88047)
@@ -238,3 +238,22 @@
 If you want to use pdb from a test in a layer that is run as a
 subprocess, then rerun the test runner selecting *just* that layer so
 that it's not run as a subprocess.
+
+
+If a test is run in a subprocess and it generates output on stderr (as
+stderrtest does), the output is ignored (but it doesn't cause a SubprocessError
+like it once did).
+
+    >>> sys.argv = [testrunner_script, '-s', 'sample2', '--tests-pattern', '(sampletests_ntd$|stderrtest)']
+    >>> testrunner.run(defaults)
+    Running sample2.sampletests_ntd.Layer tests:
+      Set up sample2.sampletests_ntd.Layer in 0.000 seconds.
+      Ran 1 tests with 0 failures and 0 errors in 0.000 seconds.
+    Running sample2.stderrtest.Layer tests:
+      Tear down sample2.sampletests_ntd.Layer ... not supported
+      Running in a subprocess.
+      Set up sample2.stderrtest.Layer in 0.000 seconds.
+      Ran 1 tests with 0 failures and 0 errors in 0.002 seconds.
+      Tear down sample2.stderrtest.Layer in 0.000 seconds.
+    Total: 2 tests, 0 failures, 0 errors in 0.197 seconds.
+    False



More information about the Zope3-Checkins mailing list