← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~gmb/launchpad/zope-layer-tagging-bug-986429 into lp:launchpad

 

Graham Binns has proposed merging lp:~gmb/launchpad/zope-layer-tagging-bug-986429 into lp:launchpad.

Requested reviews:
  Graham Binns (gmb): code
Related bugs:
  Bug #986429 in Launchpad itself: "lp.testing.tests.test_zope_test_in_subprocess.TestZopeTestInSubProcess.test deposits global "zope:layer" tag in subunit stream"
  https://bugs.launchpad.net/launchpad/+bug/986429

For more details, see:
https://code.launchpad.net/~gmb/launchpad/zope-layer-tagging-bug-986429/+merge/103476

This branch fixes bug 986429 by flushing sys.stdout and sys.stderror before ZopeTestInSubProcess.run() forks itself.

Both stdout and stderror are copied in their entirety - including their buffers - when os.fork() is called (since Python manages its own output). Not flushing before the fork means that anything in the buffer from the child will be repeated by the parent when it flushes its own stdout later on. This meant that we ended up with duplicate subunit output, which confuses anything that's trying to parse it because it looks like an extra global subunit zope:layer tag has been applied. 
-- 
https://code.launchpad.net/~gmb/launchpad/zope-layer-tagging-bug-986429/+merge/103476
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.
=== modified file 'lib/lp/testing/__init__.py'
--- lib/lp/testing/__init__.py	2012-04-17 23:03:01 +0000
+++ lib/lp/testing/__init__.py	2012-04-25 14:00:23 +0000
@@ -1070,6 +1070,12 @@
         assert isinstance(result, ZopeTestResult), (
             "result must be a Zope result object, not %r." % (result, ))
         pread, pwrite = os.pipe()
+        # We flush stdout and stderror at this point in order to avoid
+        # bug 986429; it appears that stdout and stderror get copied in
+        # full when we fork, which means that we end up with repeated
+        # output, resulting in repeated subunit output.
+        sys.stdout.flush()
+        sys.stderr.flush()
         pid = os.fork()
         if pid == 0:
             # Child.


Follow ups