From 04602ef4e0c6e3846c9e201ef9731a1072b6af66 Mon Sep 17 00:00:00 2001 From: Trenton Holmes <797416+stumpylog@users.noreply.github.com> Date: Tue, 18 Aug 2026 13:29:07 -0700 Subject: [PATCH] test(search): promote query_index to a single module-scoped fixture Three classes in test_query.py each defined an identical query_index fixture. None of these tests write documents to the index, so consolidate into one module-level, module-scoped fixture (mirroring conftest.py's index fixture rationale) instead of three copies to keep in sync. Deliberately NOT merged with conftest.py's own index fixture: that one registers tokenizers with "english" (stemming on), while these tests rely on "" (stemming off) - a real behavioral difference, not incidental. --- src/documents/tests/search/test_query.py | 31 ++++++++---------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/documents/tests/search/test_query.py b/src/documents/tests/search/test_query.py index 028aac7d6..ca79c3061 100644 --- a/src/documents/tests/search/test_query.py +++ b/src/documents/tests/search/test_query.py @@ -24,16 +24,19 @@ if TYPE_CHECKING: pytestmark = pytest.mark.search +@pytest.fixture(scope="module") +def query_index() -> tantivy.Index: + """An in-memory, unstemmed index shared read-only across this module's + parse-only tests (none of them index documents).""" + schema = build_schema() + idx = tantivy.Index(schema, path=None) + register_tokenizers(idx, "") + return idx + + class TestParseUserQuery: """parse_user_query runs the full preprocessing pipeline.""" - @pytest.fixture - def query_index(self) -> tantivy.Index: - schema = build_schema() - idx = tantivy.Index(schema, path=None) - register_tokenizers(idx, "") - return idx - def test_returns_tantivy_query(self, query_index: tantivy.Index) -> None: assert isinstance(parse_user_query(query_index, "invoice", UTC), tantivy.Query) @@ -156,13 +159,6 @@ class TestParseUserQuery: class TestParseSimpleTextHighlightQuery: """parse_simple_text_highlight_query must not raise on natural-language queries.""" - @pytest.fixture - def query_index(self) -> tantivy.Index: - schema = build_schema() - idx = tantivy.Index(schema, path=None) - register_tokenizers(idx, "") - return idx - @pytest.mark.parametrize( "raw_query", [ @@ -333,13 +329,6 @@ class TestEmitErrorContract: SearchQueryError (HTTP 400), with library-internal wording stripped from the message.""" - @pytest.fixture - def query_index(self) -> tantivy.Index: - schema = build_schema() - idx = tantivy.Index(schema, path=None) - register_tokenizers(idx, "") - return idx - def test_query_emit_error_maps_to_search_query_error( self, query_index: tantivy.Index,