From 12eb9b9abfd6c81b73f852fe79c91b6f018a42bd Mon Sep 17 00:00:00 2001 From: Trenton H <797416+stumpylog@users.noreply.github.com> Date: Mon, 30 Mar 2026 15:36:03 -0700 Subject: [PATCH] Fix: add _search_index fixture to TestDateWorkflowLocalization Tests that create or consume documents trigger the search index signal handler, which calls get_backend().add_or_update() against settings.INDEX_DIR. This class only inherited SampleDirMixin, leaving INDEX_DIR pointing at the default non-existent path and causing FileNotFoundError in CI. Added _search_index fixture to documents/tests/conftest.py: creates a temp index directory, overrides INDEX_DIR, and resets the backend singleton. Applied via @pytest.mark.usefixtures on the class. Co-Authored-By: Claude Sonnet 4.6 --- src/documents/tests/conftest.py | 17 +++++++++++++++++ src/documents/tests/test_workflows.py | 1 + 2 files changed, 18 insertions(+) diff --git a/src/documents/tests/conftest.py b/src/documents/tests/conftest.py index 7e75b9194..d1e93bf03 100644 --- a/src/documents/tests/conftest.py +++ b/src/documents/tests/conftest.py @@ -92,6 +92,23 @@ def sample_doc( ) +@pytest.fixture() +def _search_index(tmp_path: Path, settings: SettingsWrapper) -> None: + """Create a temp index directory and point INDEX_DIR at it. + + Resets the backend singleton before and after so each test gets a clean + index rather than reusing a stale singleton from another test. + """ + from documents.search import reset_backend + + index_dir = tmp_path / "index" + index_dir.mkdir() + settings.INDEX_DIR = index_dir + reset_backend() + yield + reset_backend() + + @pytest.fixture() def settings_timezone(settings: SettingsWrapper) -> zoneinfo.ZoneInfo: return zoneinfo.ZoneInfo(settings.TIME_ZONE) diff --git a/src/documents/tests/test_workflows.py b/src/documents/tests/test_workflows.py index 58d989882..0fd893a5b 100644 --- a/src/documents/tests/test_workflows.py +++ b/src/documents/tests/test_workflows.py @@ -4802,6 +4802,7 @@ class TestWebhookSecurity: @pytest.mark.django_db +@pytest.mark.usefixtures("_search_index") class TestDateWorkflowLocalization( SampleDirMixin, ):