Merge lp://staging/~yellow/zope.testing/fix-tests into lp://staging/~launchpad/zope.testing/3.9.4-fork

Proposed by Brad Crittenden
Status: Merged
Approved by: Gary Poster
Approved revision: 49
Merged at revision: 44
Proposed branch: lp://staging/~yellow/zope.testing/fix-tests
Merge into: lp://staging/~launchpad/zope.testing/3.9.4-fork
Diff against target: 1667 lines (+705/-753)
13 files modified
.bzrignore (+1/-0)
setup.py (+1/-1)
src/zope/testing/testrunner/formatter.py (+4/-0)
src/zope/testing/testrunner/options.py (+8/-4)
src/zope/testing/testrunner/runner.py (+55/-0)
src/zope/testing/testrunner/test_subunit.py (+7/-7)
src/zope/testing/testrunner/test_testrunner_subunit.py (+616/-0)
src/zope/testing/testrunner/testrunner-debugging-layer-setup.test (+1/-0)
src/zope/testing/testrunner/testrunner-layers-buff.txt (+1/-0)
src/zope/testing/testrunner/testrunner-layers-ntd.txt (+1/-0)
src/zope/testing/testrunner/testrunner-subunit-layer-setup-failures.txt (+0/-40)
src/zope/testing/testrunner/testrunner-subunit.txt (+0/-686)
src/zope/testing/testrunner/tests.py (+10/-15)
To merge this branch: bzr merge lp://staging/~yellow/zope.testing/fix-tests
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Yellow Squad code Pending
Review via email: mp+111442@code.staging.launchpad.net

Description of the change

Fix failing tests caused by bit rot and the most recent changes to include sys.stdout and sys.stderr in the subunit output.

The latter breakage was fixed by converting two subunit doctests to be unit tests instead. In addition to the morphing of the stdout and stderr streams that we are now doing, the doctest runner changes it too. That was one level too much to cleanly handle and using unit tests avoided the problem.

Updated to p15.

To post a comment you must log in.
Revision history for this message
Gary Poster (gary) wrote :

Wow! Great work. Nice changes to the tests, and thank you for cleaning up the world.

I have two comments: one each about the most predictably commentable things in the MP.

(1) For get_real_stdout and friend, would you feel better and be able to remove that apologetic comment if the code looked like this instead?

___stdout = ___stderr = None
def get_real_stdout():
    """The canonical right place to get __stdout__."""
    return ___stdout or sys.__stdout__
def get_real_stderr():
    """The canonical right place to get __stderr__."""
    return ___stderr or sys.__stderr__
def set_stdout(new):
    """Set __stdout__ so that you can clean things up later.
    Other code can get at the original value with get_real_stdout."""
    global ___stdout
    ___stdout = sys.__stdout__
    sys.__stdout__ = new
def set_stderr(new):
    """Set __stderr__ so that you can clean things up later.
    Other code can get at the original value with get_real_stderr."""
    global ___stderr
    ___stderr = sys.__stderr__
    sys.__stderr__ = new
def reset_stdout():
    global ___stdout
    result = sys.__stdout__
    sys.__stdout__ = ___stdout
    ___stdout = None
    return result
def reset_stderr():
    global ___stderr
    result = sys.__stderr__
    sys.__stderr__ = ___stderr
    ___stderr = None
    return result

Maybe you want those to mess with stdout and stderr too.

Then, in testrunner.options.get_options, instead of directly mucking with __stderr__...

                # If we are running in a subprocess then the test runner code will
                # use stderr as a communication channel back to the spawning
                # process so we shouldn't touch it.
                if '--resume-layer' not in sys.argv:
                    sys.__stderr__ = sys.stderr = StringIO()

...we say "zope.testing.testrunner.set_stderr(StringIO())"

Similarly, when we set __stdout__ in doctests, we use the functions above, and then reset them using the functions.

The advantage is that we are not doing anything at __init__ time, and everything seems a bit cleaner to me. What do you think?

(2) For the new XXX in src/zope/testing/testrunner/tests.py in which we disable the tests, please add a bug for the broken tests and mention the number. I think it's worth following the usual practice.

Thanks again!

review: Approve
50. By Brad Crittenden

Small clean up. Prevent the --require-unique warning unless -m is really used.

Revision history for this message
Graham Binns (gmb) wrote :

On 21 June 2012 18:42, Gary Poster <email address hidden> wrote:
> (1) For get_real_stdout and friend, would you feel better and be able to remove that apologetic comment if the code looked like this instead?
>[...]
> The advantage is that we are not doing anything at __init__ time, and everything seems a bit cleaner to me.  What do you think?

We tried that, and it doesn't work (or at least it doesn't work in the
case of the test that was causing the problem). The trouble is that if
we wait until call time to work out what get_real_stdout() is going to
return then we're relying on that happening before anything mucks
about with sys.__stdout__. Either way, we need to do _something_ at
init time to make this not fail in weird and wonderful ways
(particularly with anything that uses the doctest module, which pokes
something unholy onto sys.__stdout__).

> (2) For the new XXX in src/zope/testing/testrunner/tests.py in which we disable the tests, please add a bug for the broken tests and mention the number.  I think it's worth following the usual practice.

Yes, I agree; I'll take care of that tomorrow if Brad doesn't do it first.

51. By Brad Crittenden

Post review changes to make setting and resetting sys.__stdout__ and sys.__stderr__ easier.

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