I want to decorate my test to patch specific function. I'm not interested in getting the mock object as a parameter to the function.
In this example, I want to be able to omit mock_my_foo
parameter:
def my_foo(self):
print "My side_effect"
class SampleTest(TestCase):
@patch('some_module.foo', side_effect=my_foo)
def test_something(self, mock_my_foo):
pass
I'm using python 2.7
I was able to do it with specifying the new
param of patch and assigning it a mock object that had the side_effect already set:
def my_foo(self):
print "My side_effect"
class SampleTest(TestCase):
@patch('some_module.foo', new=Mock(side_effect=my_foo))
def test_something(self):
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With