调用方法后,属性为“called”的Python模拟方法仍然为False

调用方法后,属性为“called”的Python模拟方法仍然为False,python,unit-testing,mocking,patch,Python,Unit Testing,Mocking,Patch,我正在测试Python模拟库是否调用了一个方法。外部方法是: def get_abc(): get_a() get_b() get_c(False) 测试用例如下所示: @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_

我正在测试Python模拟库是否调用了一个方法。外部方法是:

def get_abc():
    get_a()
    get_b()
    get_c(False)
测试用例如下所示:

@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)
当我跟踪调试时,get_c被成功调用,但mock_meth_1的called属性从未更改。我需要做更多的工作来正确地模拟该方法吗?

您对myclass.get\c进行了两次修补,因此我不知道它将如何运行,但这可能不是您想要做的。把他们中的一个换成我的班级。得到a,你可能会没事的


您可能还会发现调用mock_meth1.assert_比调用self.assertTruemock_meth1.called更容易。

edited:fixed patching calls