import tempfile import pytest # Load test fixtures from the utils package so pytest can discover them. pytest_plugins = ["tests.utils.migration_fixtures"] @pytest.fixture def tmp_duckdb_path(tmp_path): p = tmp_path / "test.db" return str(p) @pytest.fixture def tmp_duckdb_conn(tmp_duckdb_path): # Import duckdb lazily so running pytest doesn't fail on machines # where duckdb is not installed (CI / contributor machines that don't # need the duckdb-based fixtures). If duckdb is missing, skip this # fixture at runtime when it's requested. try: import duckdb except Exception: pytest.skip("duckdb not installed, skipping duckdb fixtures") conn = duckdb.connect(database=tmp_duckdb_path) yield conn try: conn.close() except Exception: pass @pytest.fixture def monkeypatch_ai_provider(monkeypatch): """Patch ai_provider.get_embedding to return deterministic 16-dim vector.""" import ai_provider fake = [0.01] * 16 monkeypatch.setattr(ai_provider, "get_embedding", lambda text, model=None: fake) return fake @pytest.fixture def mock_odata_client(monkeypatch): """ Patch requests.Session.get for OData calls. Returns a configurable mock — set mock_odata_client.response to override. """ import requests from unittest.mock import MagicMock mock_response = MagicMock() mock_response.raise_for_status.return_value = None mock_response.json.return_value = {"value": []} class MockSession: response = mock_response def get(self, *args, **kwargs): return self.response monkeypatch.setattr(requests, "Session", MockSession) return mock_response