﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	launchpad_bug
1301	use a mock decorator for test methods that return Deferreds	davidsarah	somebody	"Using the @mock.patch decorator for Trial test methods that return Deferreds does not work, because the patch will be undone when the method returns synchronously, not when the Deferred chain completes.

We should add a decorator that can be used instead to [source:src/allmydata/test/common_util.py]. Something like:
{{{
def trialPatch(*patch_args, **patch_kwargs):
    patcher = mock.patch(*patch_args, **patch_kwargs)
    def decorator(f):
        def inner(*test_args, **test_kwargs):
            mock = patcher.__enter__()
            def cleanup(res):
                patcher.__exit__()
                return res
            test_args += (mock,)
            d = f(*test_args, **test_kwargs)
            d.addBoth(cleanup)
            return d
        return inner
    return decorator
}}}

This would require mock 0.6, I think. Thanks to ducki2p and voidspace for this code."	defect	closed	minor	undecided	code	1.8.1	somebody else's problem	mock twisted deferred test		
