Skip to content

Commit 82af667

Browse files
authored
Fix tests teardown (#20)
Fix wipe_cluster in async tests The stored node config does not include the API Key, so it had to be added explicitly.
1 parent 57cbbcb commit 82af667

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

test_elasticsearch_serverless/test_async/test_server/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ async def async_client(elasticsearch_url, elasticsearch_api_key):
4444
yield client
4545
finally:
4646
if client:
47-
wipe_cluster(client)
47+
wipe_cluster(client, elasticsearch_api_key)
4848
await client.close()

test_elasticsearch_serverless/test_server/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def sync_client_factory(elasticsearch_url, elasticsearch_api_key):
4646

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

5151
yield client
5252
finally:
@@ -55,9 +55,9 @@ def sync_client_factory(elasticsearch_url, elasticsearch_api_key):
5555

5656

5757
@pytest.fixture(scope="function")
58-
def sync_client(sync_client_factory):
58+
def sync_client(sync_client_factory, elasticsearch_api_key):
5959
try:
6060
yield sync_client_factory
6161
finally:
6262
# Wipe the cluster clean after every test execution.
63-
wipe_cluster(sync_client_factory)
63+
wipe_cluster(sync_client_factory, elasticsearch_api_key)

test_elasticsearch_serverless/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def parse_version(version: Optional[str]) -> Optional[Tuple[int, ...]]:
5353
return version_number
5454

5555

56-
def wipe_cluster(client):
56+
def wipe_cluster(client, elasticsearch_api_key):
5757
"""Wipes a cluster clean between test cases"""
5858
close_after_wipe = False
5959
try:
@@ -63,7 +63,7 @@ def wipe_cluster(client):
6363

6464
if isinstance(client, AsyncElasticsearch):
6565
node_config = client.transport.node_pool.get().config
66-
client = Elasticsearch([node_config])
66+
client = Elasticsearch(node_config, api_key=elasticsearch_api_key)
6767
close_after_wipe = True
6868
except ImportError:
6969
pass

0 commit comments

Comments
 (0)