def test_add(self, mock_add_def, mock_add): #参数的顺序与装饰的顺序是反的,与self是相同的 count = modular.Count() mock_add_def.return_value = 1 #3 mock_add.return_value = 2 #3 result1 = count.add(8, 5) result2 = modular.add_def(8, 5) print(result1, result2) self.assertEqual(result1, 13) self.assertEqual(result2, 13)
def test_add(self,mock_add_def,mock_add): # 注意:此处参数的顺序 和 装饰器的顺序正好相反!!! count = modular.Count() mock_add_def.return_value = 1 mock_add.return_value = 13 result1 = count.add(8,5) result2 = modular.add_def(8,5) print(result1,result2) self.assertEqual(result1,13) self.assertEqual(result2,13)
def test_add(self, mock_add_def): #2 mock_add_def.return_value = 1 #3 mock_add_def.side_effect = modular.add_def2 result = modular.add_def(8, 5) print(result) self.assertEqual(result, 13)
def test_add(self,mock_add_def): #2 加mock_add_def作为参数 mock_add_def.return_value = 1 #3mock_train2.py result = modular.add_def(8,5) print('---',result) self.assertEqual(result,13) mock_add_def.side_effect = modular.add_def2