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

Proposed by Graham Binns
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: 15153
Proposed branch: lp:~gmb/launchpad/zope-layer-tagging-bug-986429
Merge into: lp:launchpad
Diff against target: 16 lines (+6/-0)
1 file modified
lib/lp/testing/__init__.py (+6/-0)
To merge this branch: bzr merge lp:~gmb/launchpad/zope-layer-tagging-bug-986429
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Review via email: mp+103476@code.launchpad.net

Commit message

ZopeTestInSubProcess.run() now flushes stdout and stderror before forking itself, so as to avoid duplicated output in the subunit stream.

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Graham Binns (gmb) wrote :

Self-reviewing this change since it had input from me (gmb), Gary, Francesco, Brad and Benji.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/testing/__init__.py'
2--- lib/lp/testing/__init__.py 2012-04-17 23:03:01 +0000
3+++ lib/lp/testing/__init__.py 2012-04-25 14:00:23 +0000
4@@ -1070,6 +1070,12 @@
5 assert isinstance(result, ZopeTestResult), (
6 "result must be a Zope result object, not %r." % (result, ))
7 pread, pwrite = os.pipe()
8+ # We flush stdout and stderror at this point in order to avoid
9+ # bug 986429; it appears that stdout and stderror get copied in
10+ # full when we fork, which means that we end up with repeated
11+ # output, resulting in repeated subunit output.
12+ sys.stdout.flush()
13+ sys.stderr.flush()
14 pid = os.fork()
15 if pid == 0:
16 # Child.