diff --git a/src/mx_bluesky/hyperion/utils/context.py b/src/mx_bluesky/hyperion/utils/context.py index d76e2740d..20aa75657 100644 --- a/src/mx_bluesky/hyperion/utils/context.py +++ b/src/mx_bluesky/hyperion/utils/context.py @@ -1,6 +1,6 @@ from blueapi.core import BlueskyContext -from dodal.common.beamlines.beamline_utils import clear_devices, get_config_client -from dodal.utils import collect_factories, get_beamline_based_on_environment_variable +from dodal.common.beamlines.beamline_utils import get_config_client +from dodal.utils import get_beamline_based_on_environment_variable def setup_context(dev_mode: bool = False) -> BlueskyContext: @@ -11,12 +11,6 @@ def setup_context(dev_mode: bool = False) -> BlueskyContext: def clear_all_device_caches(context: BlueskyContext): context.unregister_all_devices() - clear_devices() - - for f in collect_factories(get_beamline_based_on_environment_variable()).values(): - if hasattr(f, "cache_clear"): - f.cache_clear() # type: ignore - get_config_client().reset_cache() diff --git a/tests/conftest.py b/tests/conftest.py index 517e2495c..b7396a762 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,11 +3,9 @@ import json import logging import os -import sys from collections.abc import Callable, Generator, Sequence from functools import partial from pathlib import Path -from types import ModuleType from typing import Any, TypedDict, TypeVar from unittest.mock import MagicMock, patch @@ -20,10 +18,8 @@ from bluesky.utils import Msg, MsgGenerator from daq_config_server import ConfigClient from dodal.beamlines import aithre, i03 -from dodal.common.beamlines import beamline_utils from dodal.common.beamlines.beamline_utils import ( clear_config_client, - clear_devices, set_config_client, ) from dodal.common.beamlines.commissioning_mode import set_commissioning_signal @@ -70,7 +66,6 @@ from dodal.devices.zocalo.zocalo_results import _NO_SAMPLE_ID from dodal.log import LOGGER as DODAL_LOGGER from dodal.log import set_up_all_logging_handlers -from dodal.utils import AnyDeviceFactory, collect_factories from event_model.documents import Event, EventDescriptor, RunStart, RunStop from ophyd_async.core import ( AsyncStatus, @@ -258,29 +253,6 @@ def ispyb_config_path(): yield ispyb_config_path -@pytest.fixture(scope="session") -def active_device_factories() -> set[AnyDeviceFactory]: - """Obtain the set of device factories that should have their caches cleared - after every test invocation. - Override this in sub-packages for the specific beamlines under test.""" - return device_factories_for_beamline(i03) - - -def device_factories_for_beamline(beamline_module: ModuleType) -> set[AnyDeviceFactory]: - return { - f - for f in collect_factories(beamline_module, include_skipped=True).values() - if hasattr(f, "cache_clear") - } - - -@pytest.fixture(scope="function", autouse=True) -def clear_device_factory_caches_after_every_test(active_device_factories): - yield None - for f in active_device_factories: - f.cache_clear() # type: ignore - - def replace_all_tmp_paths(d: dict[str, Any], tmp_path: Path): d = d.copy() for k, v in d.items(): @@ -361,8 +333,6 @@ def pytest_runtest_setup(item): def pytest_runtest_teardown(item): - if "dodal.common.beamlines.beamline_utils" in sys.modules: - sys.modules["dodal.common.beamlines.beamline_utils"].clear_devices() markers = [m.name for m in item.own_markers] if "skip_log_setup" in markers: _reset_loggers([*ALL_LOGGERS, DODAL_LOGGER]) @@ -411,7 +381,6 @@ def smargon() -> Generator[Smargon, None, None]: # Initial positions, needed for stub_offsets set_mock_value(smargon.stub_offsets.center_at_current_position.disp, 0) yield smargon - clear_devices() @pytest.fixture @@ -600,7 +569,6 @@ def locate_beamstop(_): ) yield beamstop - beamline_utils.clear_devices() @pytest.fixture @@ -610,7 +578,6 @@ def xbpm_feedback( xbpm = i03.xbpm_feedback.build(connect_immediately=True, mock=True) xbpm.trigger = MagicMock(side_effect=lambda: completed_status()) yield xbpm - beamline_utils.clear_devices() def set_up_dcm(dcm: DCM, sim_run_engine: RunEngineSimulator): @@ -661,7 +628,6 @@ def mirror_voltages(): for vc in voltages.horizontal_voltages.values(): vc.set = MagicMock(side_effect=lambda _: completed_status()) yield voltages - beamline_utils.clear_devices() @pytest.fixture @@ -675,7 +641,6 @@ def undulator_dcm(sim_run_engine, dcm, undulator) -> Generator[UndulatorDCM]: ) set_up_dcm(undulator_dcm.dcm_ref(), sim_run_engine) yield undulator_dcm - # beamline_utils.clear_devices() @pytest.fixture diff --git a/tests/unit_tests/beamlines/i24/serial/conftest.py b/tests/unit_tests/beamlines/i24/serial/conftest.py index f2da67dc4..a781f0d75 100644 --- a/tests/unit_tests/beamlines/i24/serial/conftest.py +++ b/tests/unit_tests/beamlines/i24/serial/conftest.py @@ -8,7 +8,6 @@ from dodal.devices.attenuator.attenuator import ReadOnlyAttenuator from dodal.devices.beamlines.i24.beam_center import DetectorBeamCenter from dodal.devices.zebra.zebra import Zebra -from dodal.utils import AnyDeviceFactory from ophyd_async.core import set_mock_value from mx_bluesky.beamlines.i24.serial.fixed_target.ft_utils import ChipType @@ -19,8 +18,6 @@ ) from mx_bluesky.beamlines.i24.serial.parameters.constants import DetectorName -from .....conftest import device_factories_for_beamline - TEST_PATH = Path("tests/test_data/test_daq_configuration") TEST_LUT = { @@ -33,11 +30,6 @@ def fake_generator(value): return value -@pytest.fixture(scope="session") -def active_device_factories(active_device_factories) -> set[AnyDeviceFactory]: - return active_device_factories | device_factories_for_beamline(i24) - - @pytest.fixture def dummy_params_without_pp(): oxford_defaults = get_chip_format(ChipType.Oxford) diff --git a/tests/unit_tests/common/experiment_plans/test_grid_detection_plan.py b/tests/unit_tests/common/experiment_plans/test_grid_detection_plan.py index 592394856..ef7531195 100644 --- a/tests/unit_tests/common/experiment_plans/test_grid_detection_plan.py +++ b/tests/unit_tests/common/experiment_plans/test_grid_detection_plan.py @@ -108,10 +108,6 @@ def do_grid_and_edge_detect(composite, parameters, tmp_dir): ) -@patch( - "dodal.common.beamlines.beamline_utils.active_device_is_same_type", - lambda a, b: True, -) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) def test_grid_detection_plan_runs_and_triggers_snapshots( run_engine: RunEngine, @@ -132,10 +128,6 @@ def test_grid_detection_plan_runs_and_triggers_snapshots( assert mock_save.call_count == 2 -@patch( - "dodal.common.beamlines.beamline_utils.active_device_is_same_type", - lambda a, b: True, -) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) async def test_grid_detection_plan_gives_warning_error_if_tip_not_found( run_engine: RunEngine, @@ -165,10 +157,6 @@ async def test_grid_detection_plan_gives_warning_error_if_tip_not_found( assert "No pin found" in excinfo.value.args[0] -@patch( - "dodal.common.beamlines.beamline_utils.active_device_is_same_type", - lambda a, b: True, -) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) async def test_given_when_grid_detect_then_start_position_as_expected( fake_devices: tuple[OavGridDetectionComposite, MagicMock], @@ -209,10 +197,6 @@ def decorated(): assert gridscan_params["z_start_um"] == pytest.approx(-534, abs=1) -@patch( - "dodal.common.beamlines.beamline_utils.active_device_is_same_type", - lambda a, b: True, -) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) async def test_when_grid_detection_plan_run_then_ispyb_callback_gets_correct_values( fake_devices: tuple[OavGridDetectionComposite, MagicMock], @@ -280,10 +264,6 @@ async def test_when_grid_detection_plan_run_then_ispyb_callback_gets_correct_val ) -@patch( - "dodal.common.beamlines.beamline_utils.active_device_is_same_type", - lambda a, b: True, -) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) def test_when_grid_detection_plan_run_then_grid_detection_callback_gets_correct_values( fake_devices: tuple[OavGridDetectionComposite, MagicMock], @@ -322,10 +302,6 @@ def test_when_grid_detection_plan_run_then_grid_detection_callback_gets_correct_ assert cb.x_step_size_um == cb.y_step_size_um == cb.z_step_size_um == box_size_um -@patch( - "dodal.common.beamlines.beamline_utils.active_device_is_same_type", - lambda a, b: True, -) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) def test_when_grid_detection_plan_run_with_different_omega_order_then_grid_detection_callback_gets_correct_values( fake_devices: tuple[OavGridDetectionComposite, MagicMock], @@ -405,10 +381,6 @@ def test_given_unexpected_omega_then_grid_detect_raises(tmp_path: Path): "odd", [(True), (False)], ) -@patch( - "dodal.common.beamlines.beamline_utils.active_device_is_same_type", - lambda a, b: True, -) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) @patch("mx_bluesky.common.experiment_plans.oav_grid_detection_plan.LOGGER") async def test_when_detected_grid_has_odd_y_steps_then_add_a_y_step_and_shift_grid( diff --git a/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py index c05445b1c..0c81a3adf 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py @@ -261,10 +261,6 @@ def test_calculate_motion_profile_computes_values_for_wrapped_axis( assert motion_values.distance_to_move_deg == 180.3075 * -sign -@patch( - "dodal.common.beamlines.beamline_utils.active_device_is_same_type", - lambda a, b: True, -) @patch( "mx_bluesky.hyperion.experiment_plans.rotation_scan_plan.rotation_scan_plan", autospec=True, diff --git a/tests/unit_tests/hyperion/test_baton_handler.py b/tests/unit_tests/hyperion/test_baton_handler.py index 7183c9633..b4c4878e0 100644 --- a/tests/unit_tests/hyperion/test_baton_handler.py +++ b/tests/unit_tests/hyperion/test_baton_handler.py @@ -181,13 +181,7 @@ def run_plan_in_sim(plan): faked_run_engine = MagicMock(spec=RunEngine, side_effect=run_plan_in_sim) # type: ignore - # wait_for_connection in ensure_connected creates a bunch of awaitables - # that will never be awaited by the simulator, let's not create them - def dont_connect(*args, **kwargs): - yield from bps.null() - with ( - patch("blueapi.utils.connect_devices.ensure_connected", dont_connect), patch.dict(os.environ, {"BEAMLINE": "i03"}), ): context = BlueskyContext(run_engine=faked_run_engine) diff --git a/uv.lock b/uv.lock index 8e9b2f3ca..dc417913f 100644 --- a/uv.lock +++ b/uv.lock @@ -807,8 +807,8 @@ wheels = [ [[package]] name = "dls-dodal" -version = "2.2.4.dev6+g454f60aab" -source = { git = "https://github.com/DiamondLightSource/dodal.git?rev=main#454f60aabfb68548eb1a7535adea6ce464e392c8" } +version = "2.2.4.dev9+g4ba9de171" +source = { git = "https://github.com/DiamondLightSource/dodal.git?rev=main#4ba9de17170657beb27e77ccb4a781cf311854b4" } dependencies = [ { name = "aiofiles", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" }, { name = "aiohttp", marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },