Is there a way to combine two decorators into one new decorator in python?
I realize I can just apply multiple decorators to a function, but I was curious as to whet
If you don't want to repeat yourself too much in a test suite, you could do like this::
def apply_patches(func):
@functools.wraps(func)
@mock.patch('foo.settings.USE_FAKE_CONNECTION', False)
@mock.patch('foo.settings.DATABASE_URI', 'li://foo')
@mock.patch('foo.connection.api.Session.post', autospec=True)
def _(*args, **kwargs):
return func(*args, **kwargs)
return _
now you can use that in your test suite instead of a crazy amount of decorators above each function::
def ChuckNorrisCase(unittest.TestCase):
@apply_patches
def test_chuck_pwns_none(self):
self.assertTrue(None)