"""Shared test mocks.""" import json from unittest.mock import MagicMock import pytest def load_file(filepath): """Load file.""" with open(filepath) as event_file: return event_file.read() def load_file_json(filepath): """Load json from file.""" return json.loads(load_file(filepath)) def pytest_configure(config): """Mock connectors before any test module is imported.""" # Mock antes de que pytest importe los módulos de test from unittest.mock import patch # Crear mocks persistentes mock_os = MagicMock() # Patchear en content_utils, donde se definen las clases originales os_patcher = patch( 'content_utils.connectors.opensearch.LambdaOpensearchConnector', return_value=mock_os ) # Iniciar los patches y guardarlos para cleanup os_patcher.start() # Guardar referencia para poder hacer cleanup después config._os_patcher = os_patcher def pytest_unconfigure(config): """Cleanup patches.""" if hasattr(config, '_os_patcher'): config._os_patcher.stop() @pytest.fixture def mock_event(): """Mock event.""" return load_file_json('tests/sample_event.json')