I have a test case below:
class Foo(unittest.TestCase):
@staticmethod
def my_method():
...
def test_01(self):
with patch.object(bar, 'method_to_be_mocked', side_effect=Foo.my_method):
test_stuff()
def test_02(self):
with patch.object(bar, 'method_to_be_mocked', side_effect=Foo.my_method):
test_stuff()
... ...
def test_10(self):
with patch.object(bar, 'method_to_be_mocked', side_effect=Foo.my_method):
test_stuff()
Basically I'm using Foo.my_method to mock method_to_be_mocked
The above is working fine, but as you can see I have 10 such test cases and I don't want to write "with patch.object ..." ten times. Therefore I want to use decorator and do something like this:
@patch.object(bar, 'method_to_be_mocked', side_effect=Foo.my_method):
class Foo(unittest.TestCase):
@staticmethod
def my_method():
...
def test_01(self):
test_stuff()
def test_02(self):
test_stuff()
... ...
def test_10(self):
test_stuff()
But it's telling me that Foo
is not defined?