对 python unittest 模拟有点新。我有以下代码来模拟许多函数,然后测试并调用 main()。模拟项是从 main 调用的。然而,即使 unitests 成功运行,原始函数也会被调用。为什么会发生这种情况?
@patch('utilities.etl.load')
@patch('utilities.etl.get_joined_data')
@patch('utilities.etl.transform')
@patch('utilities.etl.extract_salary')
@patch('utilities.etl.extract')
@patch('utilities.helper.get_spark_session')
def test_main(self, mock_get_sparksession, mock_extract,
mock_salary, mock_transform,
mock_join, mock_load):
mock_get_sparksession.return_value = self.spark
mock_extract.return_value = self.test_extract
mock_salary.return_value = self.test_salary
mock_transform.return_value = self.test_transform
mock_join.return_value = self.test_join
mock_load.return_value = None
main.main()