0

Kinda new to python unittest mock. I have the following code which mocks a number of functions, then tests and calls main(). The mock items are called from main. However, even though the unitests run successfully the original functions are being called as well. Why is this happening?

    @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()
Saifudeen
  • 3
  • 2
  • Either the mocks are used, or the original functions are called. At least for a single call calling both is not possible with the given test. We need more information to help you here, please try to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – MrBean Bremen Apr 22 '21 at 17:23
  • I will try to produce a minimal example. Debugging my code I notice that the real function is being executed even with a mock. Doesn't make sense. – Saifudeen Apr 23 '21 at 12:35

0 Answers0