Skip to content
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ dev = [
"types-pyyaml",
"types-pyopenssl",
"testcontainers>=4.3.1,<5",
"filelock>=3.12,<4",
"cryptography>=44.0.1",
"codespell>=2.4.1,<3",
"langcache>=0.9.0",
Expand Down
37 changes: 37 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,43 @@ def set_tokenizers_parallelism():
os.environ["TOKENIZERS_PARALLELISM"] = "false"


@pytest.fixture(scope="session", autouse=True)
def ensure_nltk_stopwords(tmp_path_factory, worker_id):
"""Pre-download the NLTK ``stopwords`` corpus once, before tests run.

Query classes that take a string ``stopwords`` value ("english" by
default) lazily download the corpus on first use. Under pytest-xdist
several workers can hit the missing corpus simultaneously and call
``nltk.download()`` concurrently, corrupting the shared ``nltk_data``
directory and producing intermittent "stopwords/english not found"
failures. Fetch it here once, serializing across workers with a file lock
so exactly one process performs the download.
"""
try:
import nltk
except ImportError:
return

def _ensure() -> None:
try:
nltk.data.find("corpora/stopwords")
except LookupError:
nltk.download("stopwords", quiet=True)

# Not running under xdist: download in-process.
if worker_id == "master":
_ensure()
return

# Under xdist: the first worker to grab the lock downloads; the others
# wait, then find the corpus already present.
from filelock import FileLock

root_tmp = tmp_path_factory.getbasetemp().parent
with FileLock(str(root_tmp / "nltk_stopwords.lock")):
_ensure()


@pytest.fixture(scope="session", autouse=True)
def redis_container(worker_id):
"""
Expand Down
11 changes: 11 additions & 0 deletions tests/integration/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_hybrid_query(index):
vector=vector,
vector_field_name=vector_field,
return_fields=return_fields,
stopwords=None,
)

results = index.query(hybrid_query)
Expand All @@ -122,6 +123,7 @@ def test_hybrid_query(index):
vector=vector,
vector_field_name=vector_field,
num_results=3,
stopwords=None,
)

results = index.query(hybrid_query)
Expand Down Expand Up @@ -177,6 +179,7 @@ def test_hybrid_query_with_filter(index):
vector_field_name=vector_field,
filter_expression=filter_expression,
return_fields=return_fields,
stopwords=None,
)

results = index.query(hybrid_query)
Expand All @@ -203,6 +206,7 @@ def test_hybrid_query_with_geo_filter(index):
vector_field_name=vector_field,
filter_expression=filter_expression,
return_fields=return_fields,
stopwords=None,
)

results = index.query(hybrid_query)
Expand All @@ -226,6 +230,7 @@ def test_hybrid_query_alpha(index, alpha):
vector=vector,
vector_field_name=vector_field,
alpha=alpha,
stopwords=None,
)

results = index.query(hybrid_query)
Expand Down Expand Up @@ -291,6 +296,7 @@ def test_hybrid_query_with_text_filter(index):
alpha=0.5,
filter_expression=filter_expression,
return_fields=["job", "description"],
stopwords=None,
)

results = index.query(hybrid_query)
Expand All @@ -309,6 +315,7 @@ def test_hybrid_query_with_text_filter(index):
alpha=0.5,
filter_expression=filter_expression,
return_fields=["description"],
stopwords=None,
)

results = index.query(hybrid_query)
Expand Down Expand Up @@ -339,6 +346,7 @@ def test_hybrid_query_word_weights(index, scorer):
return_fields=return_fields,
text_scorer=scorer,
text_weights=weights,
stopwords=None,
)

weighted_results = index.query(weighted_query)
Expand All @@ -353,6 +361,7 @@ def test_hybrid_query_word_weights(index, scorer):
return_fields=return_fields,
text_scorer=scorer,
text_weights={},
stopwords=None,
)

unweighted_results = index.query(unweighted_query)
Expand All @@ -372,6 +381,7 @@ def test_hybrid_query_word_weights(index, scorer):
return_fields=return_fields,
text_scorer=scorer,
text_weights=weights,
stopwords=None,
)

weighted_results = index.query(weighted_query)
Expand All @@ -386,6 +396,7 @@ def test_hybrid_query_word_weights(index, scorer):
return_fields=return_fields,
text_scorer=scorer,
text_weights=None,
stopwords=None,
)

new_query.set_text_weights(weights)
Expand Down
6 changes: 4 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading