On Sat, Sep 11, 2010 at 8:25 PM, Stuart Bishop <[email protected]> wrote: > On Sat, Sep 11, 2010 at 3:16 PM, Robert Collins > <[email protected]> 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 _______________________________________________ Mailing list: https://launchpad.net/~launchpad-dev Post to : [email protected] Unsubscribe : https://launchpad.net/~launchpad-dev More help : https://help.launchpad.net/ListHelp

