Python mock - zhongjiajie/zhongjiajie.github.com GitHub Wiki
越靠近mock函数对应的参数越前面
@mock.patch('airflow.hooks.dbapi_hook.DbApiHook.connection', new_callable=mock.PropertyMock)
@mock.patch('airflow.providers.exasol.hooks.exasol.pyexasol')
def test_get_conn_extra_args(self, mock_pyexasol, mock_connection):
pass
使用@mock.patch('/path/to', new_callable=mock.PropertyMock)
@mock.patch('airflow.hooks.dbapi_hook.DbApiHook.connection', new_callable=mock.PropertyMock)
@mock.patch('airflow.providers.exasol.hooks.exasol.pyexasol')
def test_get_conn_extra_args(self, mock_pyexasol, mock_connection):
self.connection.extra = json.dumps({'encryption': True})
mock_connection.return_value = self.connection
self.db_hook.get_conn()
mock_connect = mock_pyexasol.connect
mock_connect.assert_called_once()
args, kwargs = mock_connect.call_args
self.assertEqual(args, ())
self.assertEqual(kwargs['encryption'], True)