Skip to content

Fix tests teardown #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ async def async_client(elasticsearch_url, elasticsearch_api_key):
yield client
finally:
if client:
wipe_cluster(client)
wipe_cluster(client, elasticsearch_api_key)
await client.close()
6 changes: 3 additions & 3 deletions test_elasticsearch_serverless/test_server/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def sync_client_factory(elasticsearch_url, elasticsearch_api_key):

# Wipe the cluster before we start testing just in case it wasn't wiped
# cleanly from the previous run of pytest?
wipe_cluster(client)
wipe_cluster(client, elasticsearch_api_key)

yield client
finally:
Expand All @@ -55,9 +55,9 @@ def sync_client_factory(elasticsearch_url, elasticsearch_api_key):


@pytest.fixture(scope="function")
def sync_client(sync_client_factory):
def sync_client(sync_client_factory, elasticsearch_api_key):
try:
yield sync_client_factory
finally:
# Wipe the cluster clean after every test execution.
wipe_cluster(sync_client_factory)
wipe_cluster(sync_client_factory, elasticsearch_api_key)
4 changes: 2 additions & 2 deletions test_elasticsearch_serverless/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def parse_version(version: Optional[str]) -> Optional[Tuple[int, ...]]:
return version_number


def wipe_cluster(client):
def wipe_cluster(client, elasticsearch_api_key):
"""Wipes a cluster clean between test cases"""
close_after_wipe = False
try:
Expand All @@ -63,7 +63,7 @@ def wipe_cluster(client):

if isinstance(client, AsyncElasticsearch):
node_config = client.transport.node_pool.get().config
client = Elasticsearch([node_config])
client = Elasticsearch(node_config, api_key=elasticsearch_api_key)
close_after_wipe = True
except ImportError:
pass
Expand Down