Reputation: 505
I'm testing that a method gets called with the Python mock library. The outer method is this:
def get_abc():
get_a()
get_b()
get_c(False)
The test case is like this:
@mock.patch('myclass.get_a')
@mock.patch('myclass.get_b')
@mock.patch('myclass.get_c')
def test_inner_methods(self, mock_meth_1, mock_meth_2, mock_meth_3):
o = Outerclass(config_file=cfg)
o._get_abc()
self.assertTrue(mock_meth_1.called)
mock_meth_1.assert_called_with(False)
When I follow in debug, get_c() is called successfully but the called attribute of mock_meth_1 never changes. Do I need to do more to properly mock the method?
Upvotes: 0
Views: 688
Reputation: 56640
You patched myclass.get_c
twice, so I don't know how it will behave, but it's probably not what you meant to do. Switch one of them to myclass.get_a
and you'll probably be fine.
You might also find mock_meth1.assert_called()
easier than self.assertTrue(mock_meth_1.called)
.
Upvotes: 1