def test_can_dispatch_validation(self, _has_right_type, validate): """ Validator must call methods to check the file type and format. """ # Patch `open` built-in on target module m = mock_open() import runner.document_validation with patch.object(runner.document_validation, 'open', m, create=True): # Create a mock file (for the context manager) mock_file_pointer = m.return_value validator = DocumentValidatorProvider(*self.initial_data) validator.run() # Assert that the required methods were called _has_right_type.assert_called_once_with() validate.assert_called_with(mock_file_pointer)