Context
I successfully managed to mock various methods of this lib
async with AsyncElasticsearch(what,ever) as session:
patterns = await session.cat.templates(format="json")
using
mocker.patch(
"elasticsearch._async.client.cat.CatClient.templates", side_effect=mock.AsyncMock(return_value={"some":"payload"})
)
Issue
However, when it comes to async_bulk used in the very same manner
async with AsyncElasticsearch(what,ever) as session:
await async_bulk(
session,
self._rec_to_actions(item, index),
stats_only=bool(logger.getEffectiveLevel() != logging.DEBUG),
ignore_status=(200),
max_retries=2,
)
the following does not work.
mocker.patch("elasticsearch._async.helpers.async_bulk", side_effect=mock.AsyncMock(return_value=None))
elasticsearch.exceptions.ConnectionError: ConnectionError(Cannot connect to host 127.0.0.1:9200 ssl:default [Connect call failed ('127.0.0.1', 9200)]) caused by: ClientConnectorError(Cannot connect to host 127.0.0.1:9200 ssl:default [Connect call failed ('127.0.0.1', 9200)])
I tried several paths (elasticsearch.helpers.async_bulk) but without much effect. I do not understand why. related issue
Environnement
- python 3.9.7
- elasticsearch 7.14
- pytest 6.2.5