From 30173f3909be1fd3c10ae4232c52774a91a2bc73 Mon Sep 17 00:00:00 2001 From: Alexandre Teixeira <111787685+alteixeira20@users.noreply.github.com> Date: Fri, 5 Jun 2026 10:12:47 +0100 Subject: [PATCH] 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. --- tests/test_archived_sessions_model_filter.py | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_archived_sessions_model_filter.py b/tests/test_archived_sessions_model_filter.py index 921b62d..bd2153e 100644 --- a/tests/test_archived_sessions_model_filter.py +++ b/tests/test_archived_sessions_model_filter.py @@ -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(), {})