← Back to team overview

launchpad-dev team mailing list archive

Re: Lighter tests with FakeLibrarian

 

On Sat, Sep 11, 2010 at 8:25 PM, Stuart Bishop
<stuart.bishop@xxxxxxxxxxxxx> wrote:
> On Sat, Sep 11, 2010 at 3:16 PM, Robert Collins
> <robert.collins@xxxxxxxxxxxxx> wrote:
>
>> This shows a behaviour of context managers that is undesirable for test suites:
>
> I had a hard to debug failure where a context manager was being used
> as a test fixture - it did some monkey patching and then cleaned up:
>
> @contextmanager
> def with_monkey_patched_thing():
>    monkey_patch()
>    yield
>    revert_monkey_patch()
>
> The end result was the cleanup never got called if the test raised an
> exception.  The yield needs to be in a try: finally: block to ensure
> cleanup occurs.

Ah, I see, I used contextmanager wrong. Le sigh - thanks.

-Rob



References