fix(tests): make archived session filter test multipart-independent

Test-only fix continuing #2523. Makes the archived-session model-filter test independent of optional multipart packages. The red broad pytest status was classified as unrelated current dev baseline drift before merge.
This commit is contained in:
Alexandre Teixeira
2026-06-05 10:12:47 +01:00
committed by GitHub
parent f5d834b0c5
commit 30173f3909

View File

@@ -6,7 +6,9 @@ silently DROPPED "gpt-4o" (contains but does not end with the value), and
over-matched models that merely share the suffix. The sibling name filter
already uses a wildcard-escaped contains match.
"""
import sys
import tempfile
import types
import uuid
import pytest
@@ -34,11 +36,32 @@ def _route(router, path, method="GET"):
raise AssertionError(f"route not found: {path}")
def _stub_multipart_if_missing(monkeypatch):
"""Satisfy FastAPI's optional python-multipart probe.
setup_session_routes() registers form-based routes we don't exercise here.
When FastAPI analyzes their Form() params at registration time it calls
ensure_multipart_is_installed(), which raises RuntimeError if neither
python-multipart nor multipart is importable. This archived-session model
filter test must not depend on that optional package, so inject a minimal
stub (only when it's genuinely absent) to let route setup proceed.
"""
try:
import python_multipart # noqa: F401
return
except ImportError:
pass
stub = types.ModuleType("python_multipart")
stub.__version__ = "0.0.20" # FastAPI asserts __version__ > "0.0.12"
monkeypatch.setitem(sys.modules, "python_multipart", stub)
@pytest.fixture
def archived_endpoint(monkeypatch):
import routes.session_routes as sr
from unittest.mock import MagicMock
_stub_multipart_if_missing(monkeypatch)
monkeypatch.setattr(sr, "SessionLocal", _TS)
monkeypatch.setattr(sr, "effective_user", lambda request: "alice")
router = sr.setup_session_routes(MagicMock(), {})