Merge lp://staging/~bac/zope.testing/1012171 into lp://staging/~launchpad/zope.testing/3.9.4-fork

Proposed by Brad Crittenden
Status: Merged
Approved by: Brad Crittenden
Approved revision: 43
Merged at revision: 41
Proposed branch: lp://staging/~bac/zope.testing/1012171
Merge into: lp://staging/~launchpad/zope.testing/3.9.4-fork
Diff against target: 257 lines (+129/-9)
5 files modified
.bzrignore (+1/-0)
setup.py (+1/-1)
src/zope/testing/testrunner/formatter.py (+30/-2)
src/zope/testing/testrunner/options.py (+4/-2)
src/zope/testing/testrunner/test_subunit.py (+93/-4)
To merge this branch: bzr merge lp://staging/~bac/zope.testing/1012171
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+111093@code.staging.launchpad.net

Commit message

Include data written to stdout or stderr by tests into the subunit output stream.

Description of the change

Include data written to stdout or stderr by tests into the subunit output stream.

Test:

bin/test -vvt test_subunit

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

This looks great.

I'm disappointed in the hoops you had to jump through to build the content.Content objects.

review: Approve (code)
Revision history for this message
Robert Collins (lifeless) wrote :

This:
+ if msg:
+ details['STDOUT:'] = content.Content(
+ self.PLAIN_TEXT, partial(lambda x: x, msg))

Would be simpler as:
if msg:
    details['STDOUT:'] = content.text_content(msg)

(assuming msg is a unicode object, not a bytestring). If msg is a
bytestring, then:
if msg:
    details['STDOUT:'] = content.Content(content_type.UTF8_TEXT, lambda:[msg])

would be appropriate.

As it is, you're generating content objects that iterate bytes of
length 1, which will be pathologically slow, so you should change this
one way or another. Happy to chat on IRC or wherever if you need more
pointers.

-Rob

Revision history for this message
Gavin Panella (allenap) wrote :

On 19 June 2012 21:46, Robert Collins <email address hidden> wrote:
...
> (assuming msg is a unicode object, not a bytestring). If msg is a
> bytestring, then:
> if msg:
>    details['STDOUT:'] = content.Content(content_type.UTF8_TEXT, lambda:[msg])

This will keep a reference to msg in the enclosing scope. A quick look
at the code shows that msg is changed later in the function, so this
will break, hence the need for the partial() I think.

Revision history for this message
Robert Collins (lifeless) wrote :

On Wed, Jun 20, 2012 at 10:28 AM, Gavin Panella
<email address hidden> wrote:
> On 19 June 2012 21:46, Robert Collins <email address hidden> wrote:
> ...
>> (assuming msg is a unicode object, not a bytestring). If msg is a
>> bytestring, then:
>> if msg:
>>    details['STDOUT:'] = content.Content(content_type.UTF8_TEXT, lambda:[msg])
>
> This will keep a reference to msg in the enclosing scope. A quick look
> at the code shows that msg is changed later in the function, so this
> will break, hence the need for the partial() I think.

Oh! So, I'd wrap the two lines in a helper, that will break the
scoping problem and be shorter overall:

def attach(label, msg):
    if msg:
        details[label] = content.Content(content_type.UTF8_TEXT, lambda:[msg])
attach('STDOUT:, _get_new_stream_output(sys.stdout))
attach('STDERR:, _get_new_stream_output(sys.stderr))

5 lines vs 6, and less partial gymnastics ;)

-Rob

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches