import mongomock import pytest from fastapi.testclient import TestClient @pytest.fixture(scope="function") def mock_events_collection(): client = mongomock.MongoClient() db = client["micro_soc"] coll = db["events"] return coll @pytest.fixture(scope="function") def client(mock_events_collection, monkeypatch): # Patch the collection in all modules that import it before the app is imported monkeypatch.setattr("database.events_collection", mock_events_collection) monkeypatch.setattr("routes.fetch.events_collection", mock_events_collection) monkeypatch.setattr("routes.events.events_collection", mock_events_collection) monkeypatch.setattr("auth.AUTH_ENABLED", False) # Patch health check db.command so it doesn't need a real MongoDB server monkeypatch.setattr("database.db.command", lambda cmd: {"ok": 1} if cmd == "ping" else {}) from main import app return TestClient(app)