"""Fixtures for the end-to-end tests, which run against real BEC servers with the simulated MX beamline loaded. They build on the `pytest_bec_e2e` plugin; run them with pytest --start-servers --files-path tests/e2e which starts a Redis server and the BEC servers for the test session (without `--start-servers` they have to be running already). """ import pytest from bec_lib.client import BECClient from bec_lib.redis_connector import RedisConnector from bec_lib.service_config import ServiceConfig from bec_lib.tests.utils import wait_for_empty_queue from mx_bec.configs import MX_SIMULATED_DEVICES, load_mx_simulated_config, render_config from mx_bec.device_planner import SIMULATED CLIENT_SHUTDOWN_TIMEOUT_S = 10 @pytest.fixture(scope="session") def test_config_yaml_file_path(): """The device config which `bec_servers` (pytest_bec_e2e) copies next to the service config.""" return render_config(MX_SIMULATED_DEVICES) @pytest.fixture(scope="session") def simulated_bec_session(bec_redis_fixture, bec_services_config_file_path, bec_servers): """A BEC client connected to the test servers, with the simulated beamline loaded once for the whole session.""" config = ServiceConfig(bec_services_config_file_path) bec = BECClient(config, RedisConnector, forced=True, wait_for_server=True) bec.start() load_mx_simulated_config(bec, force=True) try: yield bec finally: bec.shutdown(per_thread_timeout_s=CLIENT_SHUTDOWN_TIMEOUT_S) bec._client._reset_singleton() @pytest.fixture def bec(simulated_bec_session): """The client on the simulated beamline, with an empty, running scan queue.""" bec = simulated_bec_session bec.queue.request_queue_reset() bec.queue.request_scan_continuation() wait_for_empty_queue(bec) return bec @pytest.fixture def simulated_beamline(monkeypatch): """Select the simulated beamline for the device planner.""" monkeypatch.setenv("BEAMLINE", SIMULATED)