Skip to content

Instantly share code, notes, and snippets.

@rebx
Created August 30, 2018 23:06
Show Gist options
  • Save rebx/de66de83abdd37c88b731f42e083adab to your computer and use it in GitHub Desktop.
Save rebx/de66de83abdd37c88b731f42e083adab to your computer and use it in GitHub Desktop.
creating a mock stack in python
def mock_stack(func):
@mock.patch.object(FooObject, 'method')
@mock.patch('some.module')
@functools.wraps(func)
def wrapped_func(*args, **kwargs):
return func(*args, **kwargs)
return wrapped_func
class TestSomething(unittest.TestCase):
@mock_stack
def test_some_method(self, mock_module, mock_foo_method):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment