diff --git a/tests/test_utils_pvpreload.py b/tests/test_utils_pvpreload.py index a840697aa..daf664fae 100644 --- a/tests/test_utils_pvpreload.py +++ b/tests/test_utils_pvpreload.py @@ -21,10 +21,15 @@ from slic.utils.pvpreload import * # IOC simulation @pytest.fixture(scope="module", autouse=True) def run_test_ioc(): + stop = threading.Event() + def ioc(): with MorIOC("TEST") as mor: + # Declare PVs mor.host(PV1=float, PV2=float, PV3=float, PV4=float, PV5=float, PV6=float) - while True: + + # Serve loop until 'stop' is set + while not stop.is_set(): mor.serve( PV1=1.0, PV2=2.0, @@ -35,9 +40,17 @@ def run_test_ioc(): ) time.sleep(0.1) - t = threading.Thread(target=ioc, daemon=True) + # Start IOC thread (not daemon so we can join it later) + t = threading.Thread(target=ioc) t.start() - time.sleep(1) + time.sleep(1) # Give CA time to announce PVs + + yield # <<< tests in this module run here >>> + + # --- Teardown: stop IOC and free resources --- + stop.set() + t.join(timeout=2.0) + time.sleep(0.2) def configure_logzero_for_pytest(caplog): logger.handlers.clear()