Comment 2 for bug 503698

Revision history for this message
Fernando Perez (fdo.perez) wrote : Re: [Bug 503698] [NEW] Allow embedded shells to work in doctest

On Wed, Jan 6, 2010 at 6:11 AM, Brian Granger <email address hidden> wrote:
>
> Just off the top of my head, redirecting stdout->stderr seems like it
> might have undesired
> side effects.  But, if we go this route, the try/finally should be
> replace by a context manager/with
> statement.

Good points both, thanks. We may have to live with the weird side
effects of stderr reuse, since doctest is already hijacking stdout for
its own purposes, but at least we should point it out.

And a context manager is indeed a good approach for this type of
problem. It may be a bit of overkill if all we end up needing is
really the above code, but we'll see: if we need that pattern more
than once or it gets more complicated, we'll use a CM, otherwise I
think a simply try/finally is still OK for cases like this.

Thanks again for the feedback!