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(), {})