From 679d72288f145f9db52e9f02939c30952980835d Mon Sep 17 00:00:00 2001 From: OpenCode Cabillot Date: Fri, 9 Oct 2026 12:42:21 +0000 Subject: [PATCH] =?UTF-8?q?test:=20fix=20collection=20name=20mismatch=20?= =?UTF-8?q?=E2=80=94=20env=20wiring=20centralized=20in=20conftest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause of the CI 404s: test modules mutated os.environ at import time (test_server.py set COLLECTION_NAME='test', test_integration.py 'test_mcp_maildir'). With pytest's alphabetical import order, server.COLLECTION_NAME froze at whichever value was set when server was first imported, while the fixture read os.environ at runtime — often a different name (log proof: fixture created 'test', server queried 'test_mcp_maildir' → 404 on all 6 tests). conftest.py now sets QDRANT_URL/COLLECTION_NAME/EMBEDDING_MODEL_NAME once, before any test module import; env mutation removed from test files. Unit suite still green (43 passed, 6 deselected). --- tests/conftest.py | 15 +++++++++++++++ tests/test_integration.py | 11 ++++++----- tests/test_server.py | 8 ++++---- 3 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..bcd0466 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,15 @@ +"""Shared test configuration — sets env vars ONCE before any test module runs. + +The env must be consistent for the whole pytest session: server.py freezes +COLLECTION_NAME/QDRANT_URL at import time, while the integration fixture +reads os.environ at fixture time. If any test module mutates os.environ after +that (test_server.py used to set COLLECTION_NAME='test'), the fixture creates +a different collection than the one server functions query → 404. +Keep all env wiring here so import order no longer matters. +""" + +import os + +os.environ.setdefault("QDRANT_URL", "http://localhost:6333") +os.environ.setdefault("COLLECTION_NAME", "test_mcp_maildir") +os.environ.setdefault("EMBEDDING_MODEL_NAME", "BAAI/bge-small-en-v1.5") diff --git a/tests/test_integration.py b/tests/test_integration.py index 4220fa4..c74251b 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,13 +1,14 @@ -"""Integration tests for mcp-maildir with a real Qdrant instance.""" +"""Integration tests for mcp-maildir with a real Qdrant instance. + +Env vars (QDRANT_URL, COLLECTION_NAME, EMBEDDING_MODEL_NAME) are set in +tests/conftest.py — don't set them here, they must match server.py's +import-time snapshot for every module in the session. +""" import os import uuid import pytest -os.environ["QDRANT_URL"] = "http://localhost:6333" -os.environ["COLLECTION_NAME"] = "test_mcp_maildir" -os.environ["EMBEDDING_MODEL_NAME"] = "BAAI/bge-small-en-v1.5" - from server import get_qdrant_client, get_embedding_model, search_emails, read_email from qdrant_client.http import models diff --git a/tests/test_server.py b/tests/test_server.py index 440945e..34ad7db 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -1,8 +1,8 @@ -"""Unit tests for mcp-maildir server pure functions.""" +"""Unit tests for mcp-maildir server pure functions. -import os -os.environ["QDRANT_URL"] = "http://localhost:6333" -os.environ["COLLECTION_NAME"] = "test" +Env vars are set in tests/conftest.py (shared session-wide) — see the +conftest docstring for why test modules must not touch os.environ. +""" from server import ( normalize_email_address,