0

我有两个函数:function1 和 function2 有没有办法将它们作为参数添加到参数化列表中,然后以某种方式模拟?我想要做的是用模拟的function1运行测试'name1'并用模拟的function2测试'name2'。还是编写两个单独测试的唯一方法?

    @parameterized.expand([('name1', 1, 2),
                           ('name2', 2, 2)])
    @patch('functions.function1')
    def test_data(self, _, input, expected_output, mock_func):
        # given
        mock_func.return_value = input
        # when
        output = do_something()
        # then
        self.assertEqual(output.count(), expected_output)
4

0 回答 0