Skip to content

Commit e30c9fe

Browse files
committed
add _get_unique_index_name to handle tests with same name
1 parent 0c7d911 commit e30c9fe

3 files changed

Lines changed: 22 additions & 28 deletions

File tree

.github/workflows/opensearch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
if: matrix.python-version == '3.10' && runner.os == 'Linux'
5656
run: hatch run docs
5757

58-
- name: Run tests in parallel
58+
- name: Run tests (in parallel, using 4 cores)
5959
run: hatch run test:cov-retry -n 4 # GA runner has 4 cores
6060

6161
- name: Run unit tests with lowest direct dependencies

integrations/opensearch/tests/conftest.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
import asyncio
2+
import re
23

34
import pytest
45
from haystack import Document
56

67
from haystack_integrations.document_stores.opensearch.document_store import OpenSearchDocumentStore
78

89

10+
def _get_unique_index_name(request) -> str:
11+
"""
12+
Generate a unique, valid OpenSearch index name from the test's nodeid.
13+
14+
Uses the full nodeid (e.g., 'test_document_store_async.py::TestClass::test_method')
15+
to avoid collisions when tests in different files/classes share the same method name.
16+
"""
17+
# Use nodeid for uniqueness across files/classes, sanitize for valid index name
18+
# OpenSearch index names must be lowercase and cannot contain: \, /, *, ?, ", <, >, |, space, comma, #
19+
index_name = re.sub(r"[^a-zA-Z0-9_-]", "_", request.node.nodeid).lower()
20+
# Ensure it doesn't start with -, _, or + and is not longer than 255 chars
21+
index_name = index_name.lstrip("-_+")[:255]
22+
return index_name
23+
24+
925
@pytest.fixture
1026
def document_store(request):
1127
"""
@@ -14,7 +30,7 @@ def document_store(request):
1430
"""
1531
hosts = ["https://localhost:9200"]
1632
# Use a different index for each test so we can run them in parallel
17-
index = f"{request.node.name}"
33+
index = _get_unique_index_name(request)
1834

1935
store = OpenSearchDocumentStore(
2036
hosts=hosts,
@@ -38,7 +54,7 @@ def document_store(request):
3854
@pytest.fixture
3955
def document_store_2(request):
4056
hosts = ["https://localhost:9200"]
41-
index = f"test_index_2_{request.node.name}"
57+
index = f"test_index_2_{_get_unique_index_name(request)}"
4258

4359
store = OpenSearchDocumentStore(
4460
hosts=hosts,
@@ -67,7 +83,7 @@ def document_store_readonly(request):
6783
"""
6884
hosts = ["https://localhost:9200"]
6985
# Use a different index for each test so we can run them in parallel
70-
index = f"{request.node.name}"
86+
index = _get_unique_index_name(request)
7187

7288
store = OpenSearchDocumentStore(
7389
hosts=hosts,
@@ -96,7 +112,7 @@ def document_store_embedding_dim_4_no_emb_returned(request):
96112
"""
97113
hosts = ["https://localhost:9200"]
98114
# Use a different index for each test so we can run them in parallel
99-
index = f"{request.node.name}"
115+
index = _get_unique_index_name(request)
100116

101117
store = OpenSearchDocumentStore(
102118
hosts=hosts,
@@ -121,7 +137,7 @@ def document_store_embedding_dim_4_no_emb_returned_faiss(request):
121137
"""
122138
hosts = ["https://localhost:9200"]
123139
# Use a different index for each test so we can run them in parallel
124-
index = f"{request.node.name}"
140+
index = _get_unique_index_name(request)
125141

126142
store = OpenSearchDocumentStore(
127143
hosts=hosts,

integrations/opensearch/tests/test_document_store.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -443,28 +443,6 @@ def test_write_documents_max_chunk_bytes(self, mock_bulk, document_store):
443443

444444
assert mock_bulk.call_args.kwargs["max_chunk_bytes"] == DEFAULT_MAX_CHUNK_BYTES
445445

446-
@pytest.fixture
447-
def document_store_embedding_dim_4_no_emb_returned(self, request):
448-
"""
449-
This is the most basic requirement for the child class: provide
450-
an instance of this document store so the base class can use it.
451-
"""
452-
hosts = ["https://localhost:9200"]
453-
# Use a different index for each test so we can run them in parallel
454-
index = f"{request.node.name}"
455-
456-
store = OpenSearchDocumentStore(
457-
hosts=hosts,
458-
index=index,
459-
http_auth=("admin", "admin"),
460-
verify_certs=False,
461-
embedding_dim=4,
462-
return_embedding=False,
463-
method={"space_type": "cosinesimil", "engine": "nmslib", "name": "hnsw"},
464-
)
465-
yield store
466-
store._client.indices.delete(index=index, params={"ignore": [400, 404]})
467-
468446
def test_embedding_retrieval_but_dont_return_embeddings_for_embedding_retrieval(
469447
self, document_store_embedding_dim_4_no_emb_returned: OpenSearchDocumentStore
470448
):

0 commit comments

Comments
 (0)