33import json
44import logging
55import os
6- import sys
76from collections .abc import Callable , Generator , Sequence
87from functools import partial
98from pathlib import Path
10- from types import ModuleType
119from typing import Any , TypedDict , TypeVar
1210from unittest .mock import MagicMock , patch
1311
2018from bluesky .utils import Msg , MsgGenerator
2119from daq_config_server import ConfigClient
2220from dodal .beamlines import aithre , i03
23- from dodal .common .beamlines import beamline_utils
2421from dodal .common .beamlines .beamline_utils import (
2522 clear_config_client ,
26- clear_devices ,
2723 set_config_client ,
2824)
2925from dodal .common .beamlines .commissioning_mode import set_commissioning_signal
7066from dodal .devices .zocalo .zocalo_results import _NO_SAMPLE_ID
7167from dodal .log import LOGGER as DODAL_LOGGER
7268from dodal .log import set_up_all_logging_handlers
73- from dodal .utils import AnyDeviceFactory , collect_factories
7469from event_model .documents import Event , EventDescriptor , RunStart , RunStop
7570from ophyd_async .core import (
7671 AsyncStatus ,
@@ -258,29 +253,6 @@ def ispyb_config_path():
258253 yield ispyb_config_path
259254
260255
261- @pytest .fixture (scope = "session" )
262- def active_device_factories () -> set [AnyDeviceFactory ]:
263- """Obtain the set of device factories that should have their caches cleared
264- after every test invocation.
265- Override this in sub-packages for the specific beamlines under test."""
266- return device_factories_for_beamline (i03 )
267-
268-
269- def device_factories_for_beamline (beamline_module : ModuleType ) -> set [AnyDeviceFactory ]:
270- return {
271- f
272- for f in collect_factories (beamline_module , include_skipped = True ).values ()
273- if hasattr (f , "cache_clear" )
274- }
275-
276-
277- @pytest .fixture (scope = "function" , autouse = True )
278- def clear_device_factory_caches_after_every_test (active_device_factories ):
279- yield None
280- for f in active_device_factories :
281- f .cache_clear () # type: ignore
282-
283-
284256def replace_all_tmp_paths (d : dict [str , Any ], tmp_path : Path ):
285257 d = d .copy ()
286258 for k , v in d .items ():
@@ -361,8 +333,6 @@ def pytest_runtest_setup(item):
361333
362334
363335def pytest_runtest_teardown (item ):
364- if "dodal.common.beamlines.beamline_utils" in sys .modules :
365- sys .modules ["dodal.common.beamlines.beamline_utils" ].clear_devices ()
366336 markers = [m .name for m in item .own_markers ]
367337 if "skip_log_setup" in markers :
368338 _reset_loggers ([* ALL_LOGGERS , DODAL_LOGGER ])
@@ -411,7 +381,6 @@ def smargon() -> Generator[Smargon, None, None]:
411381 # Initial positions, needed for stub_offsets
412382 set_mock_value (smargon .stub_offsets .center_at_current_position .disp , 0 )
413383 yield smargon
414- clear_devices ()
415384
416385
417386@pytest .fixture
@@ -600,7 +569,6 @@ def locate_beamstop(_):
600569 )
601570
602571 yield beamstop
603- beamline_utils .clear_devices ()
604572
605573
606574@pytest .fixture
@@ -610,7 +578,6 @@ def xbpm_feedback(
610578 xbpm = i03 .xbpm_feedback .build (connect_immediately = True , mock = True )
611579 xbpm .trigger = MagicMock (side_effect = lambda : completed_status ())
612580 yield xbpm
613- beamline_utils .clear_devices ()
614581
615582
616583def set_up_dcm (dcm : DCM , sim_run_engine : RunEngineSimulator ):
@@ -661,7 +628,6 @@ def mirror_voltages():
661628 for vc in voltages .horizontal_voltages .values ():
662629 vc .set = MagicMock (side_effect = lambda _ : completed_status ())
663630 yield voltages
664- beamline_utils .clear_devices ()
665631
666632
667633@pytest .fixture
@@ -675,7 +641,6 @@ def undulator_dcm(sim_run_engine, dcm, undulator) -> Generator[UndulatorDCM]:
675641 )
676642 set_up_dcm (undulator_dcm .dcm_ref (), sim_run_engine )
677643 yield undulator_dcm
678- # beamline_utils.clear_devices()
679644
680645
681646@pytest .fixture
0 commit comments