11import asyncio
2- import re
2+ import uuid
33
44import pytest
55from haystack import Document
66
77from haystack_integrations .document_stores .opensearch .document_store import OpenSearchDocumentStore
88
99
10- def _get_unique_index_name (request ) -> str :
10+ def _get_unique_index_name () -> str :
1111 """
12- Generate a unique, valid OpenSearch index name from the test's nodeid .
12+ Generate a unique, valid OpenSearch index name for test isolation .
1313
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.
14+ Each test gets its own index to enable parallel test execution without conflicts.
1615 """
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
16+ return f"test_{ uuid .uuid4 ().hex } "
2317
2418
2519@pytest .fixture
@@ -29,8 +23,7 @@ def document_store(request):
2923 `return_embedding` is set to True because in filters tests we compare embeddings.
3024 """
3125 hosts = ["https://localhost:9200" ]
32- # Use a different index for each test so we can run them in parallel
33- index = _get_unique_index_name (request )
26+ index = _get_unique_index_name ()
3427
3528 store = OpenSearchDocumentStore (
3629 hosts = hosts ,
@@ -54,7 +47,7 @@ def document_store(request):
5447@pytest .fixture
5548def document_store_2 (request ):
5649 hosts = ["https://localhost:9200" ]
57- index = f"test_index_2_{ _get_unique_index_name (request )} "
50+ index = f"test_index_2_{ _get_unique_index_name ()} "
5851
5952 store = OpenSearchDocumentStore (
6053 hosts = hosts ,
@@ -83,7 +76,7 @@ def document_store_readonly(request):
8376 """
8477 hosts = ["https://localhost:9200" ]
8578 # Use a different index for each test so we can run them in parallel
86- index = _get_unique_index_name (request )
79+ index = _get_unique_index_name ()
8780
8881 store = OpenSearchDocumentStore (
8982 hosts = hosts ,
@@ -111,8 +104,7 @@ def document_store_embedding_dim_4_no_emb_returned(request):
111104 A document store with embedding dimension 4 that does not return embeddings.
112105 """
113106 hosts = ["https://localhost:9200" ]
114- # Use a different index for each test so we can run them in parallel
115- index = _get_unique_index_name (request )
107+ index = _get_unique_index_name ()
116108
117109 store = OpenSearchDocumentStore (
118110 hosts = hosts ,
@@ -136,8 +128,7 @@ def document_store_embedding_dim_4_no_emb_returned_faiss(request):
136128 https://opensearch.org/docs/latest/vector-search/filter-search-knn/efficient-knn-filtering/.
137129 """
138130 hosts = ["https://localhost:9200" ]
139- # Use a different index for each test so we can run them in parallel
140- index = _get_unique_index_name (request )
131+ index = _get_unique_index_name ()
141132
142133 store = OpenSearchDocumentStore (
143134 hosts = hosts ,
0 commit comments